RE: Header problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Do you want users download the file or the zip?

do you send other headers before the download?

It's
quite a common error to set a default header in PHP at the beginning of
whatever application, while header should be used as last exit point
and never in the middle, or at the beginning, of a response.

Moreover,
if you use readfile and then zip what do you expect, multiple downloads
in one? This is not how HTTP work ... so please show more php, or
explain better what you would like to do.

Regards

> Date: Sat, 3 Oct 2009 13:30:38 +0200
> From: php.net@xxxxxxx
> To: php-general@xxxxxxxxxxxxx
> Subject:  Header problem
> 
> Hi PHP people
> 
> I have a really strange and annoying problem. I've got a site, where
> members can download music. User clicks index.php (in index.php
> there's an iframe, that opens another file), if certain check are okay
> then a popup window opens download.php, where a mp3 file is fetched
> from the server and renamed in the header, then pushed to the enduser,
> this works fine. But now I want to create zipfiles too but when a user
> downloads a zipfile it's like the whole site is freezed until download
> has completed. My guess is that this is some sort of header problem
> (see headers below), due to three headers at the same time, cause the
> class works as expected in the test page i've created. Inputs to
> correct headers would be appriciated very much :-)
> 
> Mp3 headers:
>   $new_filename = "attachment; filename=\"{$artist} - {$title}.mp3\"";
>   header('Content-Description: File Transfer');
>   header("Content-Type: application/octet-stream");
>   header("Content-Length: $size");
>   header("Content-Disposition: $new_filename");
>   header("Content-Transfer-Encoding: binary");
>   readfile($source_file);
> 
> Zip headers:
>   $zip = new zipfile();
>   $zip->add_dir(".");
>   $new_filename= "{$artist} - {$title}.mp3";
>   if(mysql_num_rows($result)) {
>     $zip->add_file($file, $new_filename);
>   }
>   header("Pragma: public");
>   header("Expires: 0");
>   header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
>   header("Cache-Control: private",false);
>   header("Content-type: application/zip");
>   #header("Content-Type: application/octet-stream");
>   header("Content-disposition: attachment; filename=\"zipTest.zip\"");
>   header('Content-Transfer-Encoding: binary');
>   ob_end_clean();
>   echo $zip->file();
> 
> Code example: http://lps.netlinq.dk/test010/test_zip.class.php
> 
> Headers (fetched with firefox add-on: live http headers)
> 
> This is headers from the site, where the problem occurs:
> 
> 1. click on the link to a title (Maxwell in this case)
> ----------------------------------------------------------
> http://lps.netlinq.dk/?action=download&track_id=357
> 
> GET /?action=download&track_id=357 HTTP/1.1
> Host: lps.netlinq.dk
> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/
> 20090803 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
> *;q=0.8
> Accept-Language: en-us,en;q=0.5
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://lps.netlinq.dk/?action=download&track_id=350
> Cookie: login_email=kim%40emax.dk;
> PHPSESSID=fbb5d6adec802766cf6f638c99ab4f1d
> 
> HTTP/1.x 200 OK
> Date: Fri, 02 Oct 2009 15:15:21 GMT
> Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch
> mod_ruby/1.2.6 Ruby/1.8.6(2007-09-24) mod_ssl/2.2.8 OpenSSL/0.9.8g
> X-Powered-By: PHP/5.2.4-2ubuntu5.6
> Expires: Thu, 19 Nov 1981 08:52:00 GMT
> Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-
> check=0
> Pragma: no-cache
> Vary: Accept-Encoding
> Content-Encoding: gzip
> Content-Length: 4250
> Keep-Alive: timeout=15, max=100
> Connection: Keep-Alive
> Content-Type: text/html
> 
> 2. I click on "download zip" (this is a link to index.php)
> if conditions are met, then a popup with download.php is activated and
> here a zip header is made
> 
> ----------------------------------------------------------
> http://lps.netlinq.dk/index.php
> 
> POST /index.php HTTP/1.1
> Host: lps.netlinq.dk
> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/
> 20090803 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
> *;q=0.8
> Accept-Language: en-us,en;q=0.5
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://lps.netlinq.dk/?action=download&track_id=357
> Cookie: login_email=kim%40emax.dk;
> PHPSESSID=fbb5d6adec802766cf6f638c99ab4f1d
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 131
> action=ask_questions&download_zipfile=1&version_id
> %5B1065%5D=1&version_id%5B1066%5D=1&version_id%5B1067%5D=1&version_id
> %5B1068%5D=1
> 
> HTTP/1.x 200 OK
> Date: Fri, 02 Oct 2009 15:15:29 GMT
> Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch
> mod_ruby/1.2.6 Ruby/1.8.6(2007-09-24) mod_ssl/2.2.8 OpenSSL/0.9.8g
> X-Powered-By: PHP/5.2.4-2ubuntu5.6
> Expires: Thu, 19 Nov 1981 08:52:00 GMT
> Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-
> check=0
> Pragma: no-cache
> Vary: Accept-Encoding
> Content-Encoding: gzip
> Content-Length: 3216
> Keep-Alive: timeout=15, max=99
> Connection: Keep-Alive
> Content-Type: text/html
> ----------------------------------------------------------
> http://lps.netlinq.dk/download.php?track_id=357&member_id=1&string=41e0cd250ca3a40598e2019fd4c813cc&kbit=320&zipfile=1
> 
> GET /download.php?
> track_id=357&member_id=1&string=41e0cd250ca3a40598e2019fd4c813cc&kbit=320&zipfile=1
> HTTP/1.1
> Host: lps.netlinq.dk
> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/
> 20090803 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
> *;q=0.8
> Accept-Language: en-us,en;q=0.5
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://lps.netlinq.dk/index.php
> Cookie: login_email=kim%40emax.dk;
> PHPSESSID=fbb5d6adec802766cf6f638c99ab4f1d
> 
> HTTP/1.x 200 OK
> Date: Fri, 02 Oct 2009 15:15:30 GMT
> Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch
> mod_ruby/1.2.6 Ruby/1.8.6(2007-09-24) mod_ssl/2.2.8 OpenSSL/0.9.8g
> X-Powered-By: PHP/5.2.4-2ubuntu5.6
> Expires: Thu, 19 Nov 1981 08:52:00 GMT
> Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-
> check=0
> Pragma: no-cache
> Content-Disposition: attachment; filename="Maxwell - Bad Habits
> (Remixes).zip"
> Content-Transfer-Encoding: binary
> Content-Length: 54234978
> Keep-Alive: timeout=15, max=98
> Connection: Keep-Alive
> Content-Type: application/zip
> ----------------------------------------------------------
> 3. as long as the zip file is downloading the site "freezes" until
> download is complete, then the link I've clicked is "activated"
> ___________________________________________________________________________
> 
> And this is the headers from the test page:
> http://lps.netlinq.dk/test010/test_zip.class.php
> http://home.emax.dk/~emax/test/test_zip.class.php
> 
> Same files, different servers
> 
> headers from test010:
> 
> http://home.emax.dk/~emax/test/test_zip.class.php?zip_to_browser=1
> 
> GET /~emax/test/test_zip.class.php?zip_to_browser=1 HTTP/1.1
> Host: home.emax.dk
> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/
> 20090803 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
> *;q=0.8
> Accept-Language: en-us,en;q=0.5
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://home.emax.dk/~emax/test/test_zip.class.php?test=15
> 
> HTTP/1.x 200 OK
> Date: Fri, 02 Oct 2009 14:31:08 GMT
> Server: Apache/1.3.37 (Unix) PHP/4.4.4
> X-Powered-By: PHP/4.4.4
> Pragma: public
> Expires: 0
> Cache-Control: must-revalidate, post-check=0, pre-check=0, private
> Content-Disposition: attachment; filename="zipTest2.zip"
> Content-Transfer-Encoding: binary
> Keep-Alive: timeout=15, max=99
> Connection: Keep-Alive
> Transfer-Encoding: chunked
> Content-Type: application/zip
> ____________________________________________________________________
> 
> headers from Netlinq:
> 
> GET /test010/test_zip.class.php?zip_to_browser=1 HTTP/1.1
> Host: lps.netlinq.dk
> User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/
> 20090803 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
> *;q=0.8
> Accept-Language: en-us,en;q=0.5
> Accept-Encoding: gzip,deflate
> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://lps.netlinq.dk/test010/test_zip.class.php?test=21
> Cookie: login_email=kim%40emax.dk;
> PHPSESSID=fbb5d6adec802766cf6f638c99ab4f1d
> 
> HTTP/1.x 200 OK
> Date: Fri, 02 Oct 2009 14:55:37 GMT
> Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch
> mod_ruby/1.2.6 Ruby/1.8.6(2007-09-24) mod_ssl/2.2.8 OpenSSL/0.9.8g
> X-Powered-By: PHP/5.2.4-2ubuntu5.6
> Pragma: public
> Expires: 0
> Cache-Control: must-revalidate, post-check=0, pre-check=0, private
> Content-Disposition: attachment; filename="zipTest2.zip"
> Content-Transfer-Encoding: binary
> Keep-Alive: timeout=15, max=100
> Connection: Keep-Alive
> Transfer-Encoding: chunked
> Content-Type: application/zip
> ____________________________________________________________________
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
 		 	   		  
_________________________________________________________________
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux