Header problem

Header problem

am 03.10.2009 13:30:38 von Kim Madsen

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&v ersion_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=41e0cd250ca3a40598e2019fd4c8 13cc&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_bro wser=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

RE: Header problem

am 03.10.2009 13:40:10 von Andrea Giammarchi

--_0ee4c6b5-d5ba-4a1a-bd70-30ce12852814_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


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=2C while header should be used as last exit point
and never in the middle=2C or at the beginning=2C of a response.

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

Regards

> Date: Sat=2C 3 Oct 2009 13:30:38 +0200
> From: php.net@emax.dk
> To: php-general@lists.php.net
> Subject: [PHP] Header problem
>=20
> Hi PHP people
>=20
> I have a really strange and annoying problem. I've got a site=2C where
> members can download music. User clicks index.php (in index.php
> there's an iframe=2C that opens another file)=2C if certain check are oka=
y
> then a popup window opens download.php=2C where a mp3 file is fetched
> from the server and renamed in the header=2C then pushed to the enduser=
=2C
> 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)=2C due to three headers at the same time=2C cause the
> class works as expected in the test page i've created. Inputs to
> correct headers would be appriciated very much :-)
>=20
> Mp3 headers:
> $new_filename =3D "attachment=3B filename=3D\"{$artist} - {$title}.mp3\=
""=3B
> header('Content-Description: File Transfer')=3B
> header("Content-Type: application/octet-stream")=3B
> header("Content-Length: $size")=3B
> header("Content-Disposition: $new_filename")=3B
> header("Content-Transfer-Encoding: binary")=3B
> readfile($source_file)=3B
>=20
> Zip headers:
> $zip =3D new zipfile()=3B
> $zip->add_dir(".")=3B
> $new_filename=3D "{$artist} - {$title}.mp3"=3B
> if(mysql_num_rows($result)) {
> $zip->add_file($file=2C $new_filename)=3B
> }
> header("Pragma: public")=3B
> header("Expires: 0")=3B
> header("Cache-Control: must-revalidate=2C post-check=3D0=2C pre-check=
=3D0")=3B
> header("Cache-Control: private"=2Cfalse)=3B
> header("Content-type: application/zip")=3B
> #header("Content-Type: application/octet-stream")=3B
> header("Content-disposition: attachment=3B filename=3D\"zipTest.zip\"")=
=3B
> header('Content-Transfer-Encoding: binary')=3B
> ob_end_clean()=3B
> echo $zip->file()=3B
>=20
> Code example: http://lps.netlinq.dk/test010/test_zip.class.php
>=20
> Headers (fetched with firefox add-on: live http headers)
>=20
> This is headers from the site=2C where the problem occurs:
>=20
> 1. click on the link to a title (Maxwell in this case)
> ----------------------------------------------------------
> http://lps.netlinq.dk/?action=3Ddownload&track_id=3D357
>=20
> GET /?action=3Ddownload&track_id=3D357 HTTP/1.1
> Host: lps.netlinq.dk
> User-Agent: Mozilla/5.0 (X11=3B U=3B Linux i686=3B en-US=3B rv:1.9.1.2) G=
ecko/
> 20090803 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2
> Accept: text/html=2Capplication/xhtml+xml=2Capplication/xml=3Bq=3D0. 9=2C*=
/
> *=3Bq=3D0.8
> Accept-Language: en-us=2Cen=3Bq=3D0.5
> Accept-Encoding: gzip=2Cdeflate
> Accept-Charset: ISO-8859-1=2Cutf-8=3Bq=3D0.7=2C*=3Bq=3D0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://lps.netlinq.dk/?action=3Ddownload&track_id=3D350
> Cookie: login_email=3Dkim%40emax.dk=3B
> PHPSESSID=3Dfbb5d6adec802766cf6f638c99ab4f1d
>=20
> HTTP/1.x 200 OK
> Date: Fri=2C 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=2C 19 Nov 1981 08:52:00 GMT
> Cache-Control: no-store=2C no-cache=2C must-revalidate=2C post-check=3D0=
=2C pre-
> check=3D0
> Pragma: no-cache
> Vary: Accept-Encoding
> Content-Encoding: gzip
> Content-Length: 4250
> Keep-Alive: timeout=3D15=2C max=3D100
> Connection: Keep-Alive
> Content-Type: text/html
>=20
> 2. I click on "download zip" (this is a link to index.php)
> if conditions are met=2C then a popup with download.php is activated and
> here a zip header is made
>=20
> ----------------------------------------------------------
> http://lps.netlinq.dk/index.php
>=20
> POST /index.php HTTP/1.1
> Host: lps.netlinq.dk
> User-Agent: Mozilla/5.0 (X11=3B U=3B Linux i686=3B en-US=3B rv:1.9.1.2) G=
ecko/
> 20090803 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2
> Accept: text/html=2Capplication/xhtml+xml=2Capplication/xml=3Bq=3D0. 9=2C*=
/
> *=3Bq=3D0.8
> Accept-Language: en-us=2Cen=3Bq=3D0.5
> Accept-Encoding: gzip=2Cdeflate
> Accept-Charset: ISO-8859-1=2Cutf-8=3Bq=3D0.7=2C*=3Bq=3D0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://lps.netlinq.dk/?action=3Ddownload&track_id=3D357
> Cookie: login_email=3Dkim%40emax.dk=3B
> PHPSESSID=3Dfbb5d6adec802766cf6f638c99ab4f1d
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 131
> action=3Dask_questions&download_zipfile=3D1&version_id
> %5B1065%5D=3D1&version_id%5B1066%5D=3D1&version_id%5B1067%5D =3D1&version_=
id
> %5B1068%5D=3D1
>=20
> HTTP/1.x 200 OK
> Date: Fri=2C 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=2C 19 Nov 1981 08:52:00 GMT
> Cache-Control: no-store=2C no-cache=2C must-revalidate=2C post-check=3D0=
=2C pre-
> check=3D0
> Pragma: no-cache
> Vary: Accept-Encoding
> Content-Encoding: gzip
> Content-Length: 3216
> Keep-Alive: timeout=3D15=2C max=3D99
> Connection: Keep-Alive
> Content-Type: text/html
> ----------------------------------------------------------
> http://lps.netlinq.dk/download.php?track_id=3D357&member_id= 3D1&string=3D=
41e0cd250ca3a40598e2019fd4c813cc&kbit=3D320&zipfile=3D1
>=20
> GET /download.php?
> track_id=3D357&member_id=3D1&string=3D41e0cd250ca3a40598e201 9fd4c813cc&kb=
it=3D320&zipfile=3D1
> HTTP/1.1
> Host: lps.netlinq.dk
> User-Agent: Mozilla/5.0 (X11=3B U=3B Linux i686=3B en-US=3B rv:1.9.1.2) G=
ecko/
> 20090803 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2
> Accept: text/html=2Capplication/xhtml+xml=2Capplication/xml=3Bq=3D0. 9=2C*=
/
> *=3Bq=3D0.8
> Accept-Language: en-us=2Cen=3Bq=3D0.5
> Accept-Encoding: gzip=2Cdeflate
> Accept-Charset: ISO-8859-1=2Cutf-8=3Bq=3D0.7=2C*=3Bq=3D0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://lps.netlinq.dk/index.php
> Cookie: login_email=3Dkim%40emax.dk=3B
> PHPSESSID=3Dfbb5d6adec802766cf6f638c99ab4f1d
>=20
> HTTP/1.x 200 OK
> Date: Fri=2C 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=2C 19 Nov 1981 08:52:00 GMT
> Cache-Control: no-store=2C no-cache=2C must-revalidate=2C post-check=3D0=
=2C pre-
> check=3D0
> Pragma: no-cache
> Content-Disposition: attachment=3B filename=3D"Maxwell - Bad Habits
> (Remixes).zip"
> Content-Transfer-Encoding: binary
> Content-Length: 54234978
> Keep-Alive: timeout=3D15=2C max=3D98
> Connection: Keep-Alive
> Content-Type: application/zip
> ----------------------------------------------------------
> 3. as long as the zip file is downloading the site "freezes" until
> download is complete=2C then the link I've clicked is "activated"
> ____________________________________________________________ _____________=
__
>=20
> 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
>=20
> Same files=2C different servers
>=20
> headers from test010:
>=20
> http://home.emax.dk/~emax/test/test_zip.class.php?zip_to_bro wser=3D1
>=20
> GET /~emax/test/test_zip.class.php?zip_to_browser=3D1 HTTP/1.1
> Host: home.emax.dk
> User-Agent: Mozilla/5.0 (X11=3B U=3B Linux i686=3B en-US=3B rv:1.9.1.2) G=
ecko/
> 20090803 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2
> Accept: text/html=2Capplication/xhtml+xml=2Capplication/xml=3Bq=3D0. 9=2C*=
/
> *=3Bq=3D0.8
> Accept-Language: en-us=2Cen=3Bq=3D0.5
> Accept-Encoding: gzip=2Cdeflate
> Accept-Charset: ISO-8859-1=2Cutf-8=3Bq=3D0.7=2C*=3Bq=3D0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://home.emax.dk/~emax/test/test_zip.class.php?test=3D15
>=20
> HTTP/1.x 200 OK
> Date: Fri=2C 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=2C post-check=3D0=2C pre-check=3D0=2C priv=
ate
> Content-Disposition: attachment=3B filename=3D"zipTest2.zip"
> Content-Transfer-Encoding: binary
> Keep-Alive: timeout=3D15=2C max=3D99
> Connection: Keep-Alive
> Transfer-Encoding: chunked
> Content-Type: application/zip
> ____________________________________________________________ ________
>=20
> headers from Netlinq:
>=20
> GET /test010/test_zip.class.php?zip_to_browser=3D1 HTTP/1.1
> Host: lps.netlinq.dk
> User-Agent: Mozilla/5.0 (X11=3B U=3B Linux i686=3B en-US=3B rv:1.9.1.2) G=
ecko/
> 20090803 Ubuntu/9.04 (jaunty) Shiretoko/3.5.2
> Accept: text/html=2Capplication/xhtml+xml=2Capplication/xml=3Bq=3D0. 9=2C*=
/
> *=3Bq=3D0.8
> Accept-Language: en-us=2Cen=3Bq=3D0.5
> Accept-Encoding: gzip=2Cdeflate
> Accept-Charset: ISO-8859-1=2Cutf-8=3Bq=3D0.7=2C*=3Bq=3D0.7
> Keep-Alive: 300
> Connection: keep-alive
> Referer: http://lps.netlinq.dk/test010/test_zip.class.php?test=3D21
> Cookie: login_email=3Dkim%40emax.dk=3B
> PHPSESSID=3Dfbb5d6adec802766cf6f638c99ab4f1d
>=20
> HTTP/1.x 200 OK
> Date: Fri=2C 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=2C post-check=3D0=2C pre-check=3D0=2C priv=
ate
> Content-Disposition: attachment=3B filename=3D"zipTest2.zip"
> Content-Transfer-Encoding: binary
> Keep-Alive: timeout=3D15=2C max=3D100
> Connection: Keep-Alive
> Transfer-Encoding: chunked
> Content-Type: application/zip
> ____________________________________________________________ ________
>=20
> --=20
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe=2C visit: http://www.php.net/unsub.php
>=20
=0A=
____________________________________________________________ _____=0A=
Windows Live: Friends get your Flickr=2C Yelp=2C and Digg updates when they=
e-mail you.=0A=
http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/so=
cial-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL:en -xm:SI_SB_3:092=
010=

--_0ee4c6b5-d5ba-4a1a-bd70-30ce12852814_--

Re: Header problem

am 03.10.2009 16:21:41 von kranthi

Thats a lot of headers to read..
At a first glance I can see that you did not specify a content-length
header. this is a must and must be equal to the size of the file in
bytes

--
Kranthi.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Header problem

am 04.10.2009 18:30:29 von Ashley Sheridan

--=-+VmHZ196hati6eIVW/8n
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Sun, 2009-10-04 at 18:10 +0200, Kim Madsen wrote:

> Hi kranthi
>
> kranthi wrote on 2009-10-03 16:21:
> > Thats a lot of headers to read..
> > At a first glance I can see that you did not specify a content-length
> > header. this is a must and must be equal to the size of the file in
> > bytes
>
> I've noticed that too, but it's impossiple to determine the length of
> the zipfile, when creating the file in memory.
>
> Instead I'm now writing the file to disk and uses filesize on the
> zipfile to get the length for Content-Length, then I use
> readfile("zipfile.zip") instead of echo $zip->file(); But the result is
> still the same :-/
>
> Kind regards
> Kim
>


Afaik, the content length header is not necessary, but it will cause
problems if it's set and it's wrong.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-+VmHZ196hati6eIVW/8n--

RE: Header problem

am 04.10.2009 18:49:13 von Andrea Giammarchi

--_1f35592e-8022-4873-af5c-5f5fa11ab4bd_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable



> Header must come first (before you output anything) or you get a parse=20
> error

I try to better explain ...

HTTP works like this: you ask something=2C you receive something=2C html an=
d texts are just one option.

Your example page mess up html=2C zip=2C everything=2C because when you dow=
nload a file you still have the rest of the page sent in the output.

A download should have ONLY file related info/headers and nothing else in t=
he output ... echo/print in the middle of the code before an header is an e=
rror=2C everything in output before an header is an error=2C everything aft=
er headers that is not related to that header is an error=2C got my point?

To decide how a page should behave=2C you must be able to do not produce an=
ything except the expected output with expected headers=2C that's why I hav=
e said headers are fundamental for a response=2C we cannot play with output=
s however we want.=20

As summary=2C once you have created and tried a dedicated page without a si=
ngle white space or print before=2C during=2C or after the dedicated downlo=
ad stuff=2C I'll try to understand where is the error.
Otherwise it could be everything=2C and I am against "magic behaviors" ... =
you need to download? Well=2C create a file which aims id to download and n=
othing else=2C or you gonna constantly find these kind of problems in your =
applications.

Regards
=0A=
____________________________________________________________ _____=0A=
Keep your friends updated=97even when you=92re not signed in.=0A=
http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/so=
cial-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL:en -xm:SI_SB_5:092=
010=

--_1f35592e-8022-4873-af5c-5f5fa11ab4bd_--

RE: Header problem

am 04.10.2009 18:51:47 von Andrea Giammarchi

--_3e199a65-fdd9-4546-9d8f-85828973ef6e_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



> Afaik=2C the content length header is not necessary=2C but it will cause
> problems if it's set and it's wrong.

correct=2C missed Content-Length means the classic download with useless pr=
ogress bar and undefined estimation time=2C problematic for preloader as we=
ll in case of images=2C swf=2C generic data=2C etc.

Content_length should be always present and it should be correct=2C but obv=
iously if there are print or echo or other outputs non file related=2C Cont=
ent-Length can simply mess up the response.
=0A=
____________________________________________________________ _____=0A=
Windows Live: Friends get your Flickr=2C Yelp=2C and Digg updates when they=
e-mail you.=0A=
http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/so=
cial-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL:en -xm:SI_SB_3:092=
010=

--_3e199a65-fdd9-4546-9d8f-85828973ef6e_--

Re: Header problem

am 04.10.2009 19:09:35 von Kim Madsen

Hello Andrea

Andrea Giammarchi wrote on 2009-10-04 18:49:
>
> > Header must come first (before you output anything) or you get a parse
> > error
>
> I try to better explain ...
>
> HTTP works like this: you ask something, you receive something, html and
> texts are just one option.

Got it so far

> Your example page mess up html, zip, everything, because when you
> download a file you still have the rest of the page sent in the output.

Nops, not really.

index.php:
print stuff
do stuff
open download.php in a _new_ window.
print more stuff
page end

this should be possible, right? Two different headers for two different
pages.

> A download should have ONLY file related info/headers and nothing else
> in the output ... echo/print in the middle of the code before an header
> is an error, everything in output before an header is an error,
> everything after headers that is not related to that header is an error,
> got my point?

Jep! And that's actually what I do. What I could, is to add exit; after
the headers have been sent and the file have been pushed. I do an update
of the database to tell the system that the files in the zipfile has
been downloaded.

> To decide how a page should behave, you must be able to do not produce
> anything except the expected output with expected headers, that's why I
> have said headers are fundamental for a response, we cannot play with
> outputs however we want.

The only output is the headers of the zipfile:

header('Accept-Ranges: bytes');
header("Content-Type: application/zip");
header("Content-Length: $size");
header("Content-disposition: attachment;
filename=\"".basename($zip_filename)."\"");
header("Content-Transfer-Encoding: binary");
readfile($filename);

// we need to reload top5 to have a current view
unset($_SESSION['top5']);
$_SESSION['reload_top5'] = 1;

// NOTE second param shall be an array, not a variable when
downloading zip files
download_completed($member_id, $downloaded_version_ids);

Wouldn't you say this is okay?

> As summary, once you have created and tried a dedicated page without a
> single white space or print before, during, or after the dedicated
> download stuff, I'll try to understand where is the error.
> Otherwise it could be everything, and I am against "magic behaviors" ...
> you need to download? Well, create a file which aims id to download and
> nothing else, or you gonna constantly find these kind of problems in
> your applications.

I believe the testpage does forfill that request? Or do you mean otherwise?

Kind regards
Kim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Header problem

am 04.10.2009 19:36:40 von Andrea Giammarchi

--_8e222d92-3205-4b4e-a66e-5ff092216b64_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Unless I am missing something=2C your page has too many if and it always en=
ds up with print something ... but there is no exit after the download=2C s=
o the zip will have extra output included without a reason ... which is an =
error=2C imho=2C dunno how else explain if you can't see your print "links"=
at the end of the page ...=20

Regards

> Date: Sun=2C 4 Oct 2009 19:09:35 +0200
> From: php.net@emax.dk
> To: php-general@lists.php.net
> Subject: Re: [PHP] Header problem
>=20
> Hello Andrea
>=20
> Andrea Giammarchi wrote on 2009-10-04 18:49:
> >=20
> > > Header must come first (before you output anything) or you get a par=
se
> > > error
> >=20
> > I try to better explain ...
> >=20
> > HTTP works like this: you ask something=2C you receive something=2C htm=
l and=20
> > texts are just one option.
>=20
> Got it so far
>=20
> > Your example page mess up html=2C zip=2C everything=2C because when you=
=20
> > download a file you still have the rest of the page sent in the output.
>=20
> Nops=2C not really.
>=20
> index.php:
> print stuff
> do stuff
> open download.php in a _new_ window.
> print more stuff
> page end
>=20
> this should be possible=2C right? Two different headers for two different=
=20
> pages.
>=20
> > A download should have ONLY file related info/headers and nothing else=
=20
> > in the output ... echo/print in the middle of the code before an header=
=20
> > is an error=2C everything in output before an header is an error,
> > everything after headers that is not related to that header is an error=
,
> > got my point?
>=20
> Jep! And that's actually what I do. What I could=2C is to add exit=3B aft=
er=20
> the headers have been sent and the file have been pushed. I do an update=
=20
> of the database to tell the system that the files in the zipfile has=20
> been downloaded.
>=20
> > To decide how a page should behave=2C you must be able to do not produc=
e=20
> > anything except the expected output with expected headers=2C that's why=
I=20
> > have said headers are fundamental for a response=2C we cannot play with=
=20
> > outputs however we want.
>=20
> The only output is the headers of the zipfile:
>=20
> header('Accept-Ranges: bytes')=3B
> header("Content-Type: application/zip")=3B
> header("Content-Length: $size")=3B
> header("Content-disposition: attachment;
> filename=3D\"".basename($zip_filename)."\"")=3B
> header("Content-Transfer-Encoding: binary")=3B
> readfile($filename)=3B
>=20
> // we need to reload top5 to have a current view
> unset($_SESSION['top5'])=3B
> $_SESSION['reload_top5'] =3D 1=3B
>=20
> // NOTE second param shall be an array=2C not a variable when=20
> downloading zip files
> download_completed($member_id=2C $downloaded_version_ids)=3B
>=20
> Wouldn't you say this is okay?
>=20
> > As summary=2C once you have created and tried a dedicated page without =
a=20
> > single white space or print before=2C during=2C or after the dedicated=
=20
> > download stuff=2C I'll try to understand where is the error.
> > Otherwise it could be everything=2C and I am against "magic behaviors" =
....=20
> > you need to download? Well=2C create a file which aims id to download a=
nd=20
> > nothing else=2C or you gonna constantly find these kind of problems in=
=20
> > your applications.
>=20
> I believe the testpage does forfill that request? Or do you mean otherwis=
e?
>=20
> Kind regards
> Kim
>=20
> --=20
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe=2C visit: http://www.php.net/unsub.php
>=20
=0A=
____________________________________________________________ _____=0A=
Windows Live Hotmail: Your friends can get your Facebook updates=2C right f=
rom Hotmail=AE.=0A=
http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/so=
cial-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL:en -xm:SI_SB_4:092=
009=

--_8e222d92-3205-4b4e-a66e-5ff092216b64_--

Re: Header problem

am 04.10.2009 20:19:33 von Tommy Pham

---- Original Message ----
> From: Kim Madsen
> To: php-general@lists.php.net
> Sent: Sun, October 4, 2009 9:10:36 AM
> Subject: Re: [PHP] Header problem
>
> Hi kranthi
>
> kranthi wrote on 2009-10-03 16:21:
> > Thats a lot of headers to read..
> > At a first glance I can see that you did not specify a content-length
> > header. this is a must and must be equal to the size of the file in
> > bytes
>
> I've noticed that too, but it's impossiple to determine the length of the
> zipfile, when creating the file in memory.
>
> Instead I'm now writing the file to disk and uses filesize on the zipfile to get
> the length for Content-Length, then I use readfile("zipfile.zip") instead of
> echo $zip->file(); But the result is still the same :-/
>
> Kind regards
> Kim
>
> -- PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

If you want to take advantage of chunked-transfer encoding, you can not specify 'content-length'.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Header problem

am 05.10.2009 18:10:57 von Kim Madsen

Hi Andrea

Andrea Giammarchi wrote on 2009-10-04 19:36:
> Unless I am missing something, your page has too many if and it always
> ends up with print something ... but there is no exit after the
> download, so the zip will have extra output included without a reason
> ... which is an error, imho, dunno how else explain if you can't see
> your print "links" at the end of the page ...

Sorry, the .phps file wasn't updated, but the page still works as
expected even though I've printed stuff after the header (i tested that
just for fun).

I'm thinking I'll try and look at the included files, this is what
happends before the headers are trown:

session_start();
$version_id = $_REQUEST['version_id'];
$track_id = $_REQUEST['track_id'];
$member_id = $_REQUEST['member_id'];
$string = $_REQUEST['string'];
$zipfile = $_REQUEST['zipfile'];

if($DOWNLOAD_OK) {
include "inc/connect.inc";
include "inc/functions.inc";
include "inc/default_functions.inc";

As you said earlier, spaces could do wierd stuff to a header

Also switching between utf-8 and latin-1 character sets can make php
choke, I've experienced that before with sessions.

Kind regards
Kim

> > Date: Sun, 4 Oct 2009 19:09:35 +0200
> > From: php.net@emax.dk
> > To: php-general@lists.php.net
> > Subject: Re: [PHP] Header problem
> >
> > Hello Andrea
> >
> > Andrea Giammarchi wrote on 2009-10-04 18:49:
> > >
> > > > Header must come first (before you output anything) or you get a
> parse
> > > > error
> > >
> > > I try to better explain ...
> > >
> > > HTTP works like this: you ask something, you receive something,
> html and
> > > texts are just one option.
> >
> > Got it so far
> >
> > > Your example page mess up html, zip, everything, because when you
> > > download a file you still have the rest of the page sent in the output.
> >
> > Nops, not really.
> >
> > index.php:
> > print stuff
> > do stuff
> > open download.php in a _new_ window.
> > print more stuff
> > page end
> >
> > this should be possible, right? Two different headers for two different
> > pages.
> >
> > > A download should have ONLY file related info/headers and nothing else
> > > in the output ... echo/print in the middle of the code before an
> header
> > > is an error, everything in output before an header is an error,
> > > everything after headers that is not related to that header is an
> error,
> > > got my point?
> >
> > Jep! And that's actually what I do. What I could, is to add exit; after
> > the headers have been sent and the file have been pushed. I do an update
> > of the database to tell the system that the files in the zipfile has
> > been downloaded.
> >
> > > To decide how a page should behave, you must be able to do not produce
> > > anything except the expected output with expected headers, that's
> why I
> > > have said headers are fundamental for a response, we cannot play with
> > > outputs however we want.
> >
> > The only output is the headers of the zipfile:
> >
> > header('Accept-Ranges: bytes');
> > header("Content-Type: application/zip");
> > header("Content-Length: $size");
> > header("Content-disposition: attachment;
> > filename=\"".basename($zip_filename)."\"");
> > header("Content-Transfer-Encoding: binary");
> > readfile($filename);
> >
> > // we need to reload top5 to have a current view
> > unset($_SESSION['top5']);
> > $_SESSION['reload_top5'] = 1;
> >
> > // NOTE second param shall be an array, not a variable when
> > downloading zip files
> > download_completed($member_id, $downloaded_version_ids);
> >
> > Wouldn't you say this is okay?
> >
> > > As summary, once you have created and tried a dedicated page without a
> > > single white space or print before, during, or after the dedicated
> > > download stuff, I'll try to understand where is the error.
> > > Otherwise it could be everything, and I am against "magic
> behaviors" ...
> > > you need to download? Well, create a file which aims id to download
> and
> > > nothing else, or you gonna constantly find these kind of problems in
> > > your applications.
> >
> > I believe the testpage does forfill that request? Or do you mean
> otherwise?
> >
> > Kind regards
> > Kim
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
> ------------------------------------------------------------ ------------
> Windows Live Hotmail: Your friends can get your Facebook updates, right
> from Hotmail®.
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Header problem

am 05.10.2009 18:19:02 von Ashley Sheridan

--=-GdAByWdbV1xFvGp+7D3U
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Mon, 2009-10-05 at 18:10 +0200, Kim Madsen wrote:

> Hi Andrea
>=20
> Andrea Giammarchi wrote on 2009-10-04 19:36:
> > Unless I am missing something, your page has too many if and it always=20
> > ends up with print something ... but there is no exit after the=20
> > download, so the zip will have extra output included without a reason=20
> > ... which is an error, imho, dunno how else explain if you can't see=20
> > your print "links" at the end of the page ...
>=20
> Sorry, the .phps file wasn't updated, but the page still works as=20
> expected even though I've printed stuff after the header (i tested that=20
> just for fun).
>=20
> I'm thinking I'll try and look at the included files, this is what=20
> happends before the headers are trown:
>=20
> session_start();
> $version_id =3D $_REQUEST['version_id'];
> $track_id =3D $_REQUEST['track_id'];
> $member_id =3D $_REQUEST['member_id'];
> $string =3D $_REQUEST['string'];
> $zipfile =3D $_REQUEST['zipfile'];
>=20
> if($DOWNLOAD_OK) {
> include "inc/connect.inc";
> include "inc/functions.inc";
> include "inc/default_functions.inc";
>=20
> As you said earlier, spaces could do wierd stuff to a header
>=20
> Also switching between utf-8 and latin-1 character sets can make php=20
> choke, I've experienced that before with sessions.
>=20
> Kind regards
> Kim
>=20
> > > Date: Sun, 4 Oct 2009 19:09:35 +0200
> > > From: php.net@emax.dk
> > > To: php-general@lists.php.net
> > > Subject: Re: [PHP] Header problem
> > >
> > > Hello Andrea
> > >
> > > Andrea Giammarchi wrote on 2009-10-04 18:49:
> > > >
> > > > > Header must come first (before you output anything) or you get a=
=20
> > parse
> > > > > error
> > > >
> > > > I try to better explain ...
> > > >
> > > > HTTP works like this: you ask something, you receive something,=20
> > html and
> > > > texts are just one option.
> > >
> > > Got it so far
> > >
> > > > Your example page mess up html, zip, everything, because when you
> > > > download a file you still have the rest of the page sent in the ou=
tput.
> > >
> > > Nops, not really.
> > >
> > > index.php:
> > > print stuff
> > > do stuff
> > > open download.php in a _new_ window.
> > > print more stuff
> > > page end
> > >
> > > this should be possible, right? Two different headers for two differ=
ent
> > > pages.
> > >
> > > > A download should have ONLY file related info/headers and nothing =
else
> > > > in the output ... echo/print in the middle of the code before an=20
> > header
> > > > is an error, everything in output before an header is an error,
> > > > everything after headers that is not related to that header is an=20
> > error,
> > > > got my point?
> > >
> > > Jep! And that's actually what I do. What I could, is to add exit; af=
ter
> > > the headers have been sent and the file have been pushed. I do an up=
date
> > > of the database to tell the system that the files in the zipfile has
> > > been downloaded.
> > >
> > > > To decide how a page should behave, you must be able to do not pro=
duce
> > > > anything except the expected output with expected headers, that's=20
> > why I
> > > > have said headers are fundamental for a response, we cannot play w=
ith
> > > > outputs however we want.
> > >
> > > The only output is the headers of the zipfile:
> > >
> > > header('Accept-Ranges: bytes');
> > > header("Content-Type: application/zip");
> > > header("Content-Length: $size");
> > > header("Content-disposition: attachment;
> > > filename=3D\"".basename($zip_filename)."\"");
> > > header("Content-Transfer-Encoding: binary");
> > > readfile($filename);
> > >
> > > // we need to reload top5 to have a current view
> > > unset($_SESSION['top5']);
> > > $_SESSION['reload_top5'] =3D 1;
> > >
> > > // NOTE second param shall be an array, not a variable when
> > > downloading zip files
> > > download_completed($member_id, $downloaded_version_ids);
> > >
> > > Wouldn't you say this is okay?
> > >
> > > > As summary, once you have created and tried a dedicated page witho=
ut a
> > > > single white space or print before, during, or after the dedicated
> > > > download stuff, I'll try to understand where is the error.
> > > > Otherwise it could be everything, and I am against "magic=20
> > behaviors" ...
> > > > you need to download? Well, create a file which aims id to downloa=
d=20
> > and
> > > > nothing else, or you gonna constantly find these kind of problems =
in
> > > > your applications.
> > >
> > > I believe the testpage does forfill that request? Or do you mean=20
> > otherwise?
> > >
> > > Kind regards
> > > Kim
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >=20
> > ------------------------------------------------------------ -----------=
-
> > Windows Live Hotmail: Your friends can get your Facebook updates, right=
=20
> > from Hotmail®.=20
> > on/social-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON: WL:en-xm:SI_SB_=
4:092009>
>=20
>=20

There's a useful function called headers_sent() which checks to see if
the headers have already been sent to the browser. This might be a good
place to throw into your code at various points to check and see if
something is being written which you don't expect.

Also, one method I use, is to write the content you would be 'printing'
to a file rather than the screen. Open the file in a plain text editor
and look at the first few characters. Usually these give you an idea of
the format of the file, but if you're seeing plain text (like error
messages for example) you know you made a mistake with the output.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-GdAByWdbV1xFvGp+7D3U--

RE: Header problem

am 05.10.2009 18:24:38 von Andrea Giammarchi

--_7beee6bb-7a82-4f02-aa5c-3d8a8f884908_
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable



> Sorry=2C the .phps file wasn't updated=2C but the page still works as=20
> expected even though I've printed stuff after the header (i tested that=20
> just for fun).

I already said magic behavior are not part of my developed code=2C unrelate=
d output is an error=2C even if the download work=2C it is an error.


>=20
> I'm thinking I'll try and look at the included files=2C this is what=20
> happends before the headers are trown:
>=20
> session_start()=3B
> $version_id =3D $_REQUEST['version_id']=3B
> $track_id =3D $_REQUEST['track_id']=3B
> $member_id =3D $_REQUEST['member_id']=3B
> $string =3D $_REQUEST['string']=3B
> $zipfile =3D $_REQUEST['zipfile']=3B
>=20
> if($DOWNLOAD_OK) {
> include "inc/connect.inc"=3B
> include "inc/functions.inc"=3B
> include "inc/default_functions.inc"=3B
>=20
> As you said earlier=2C spaces could do wierd stuff to a header
>=20
> Also switching between utf-8 and latin-1 character sets can make php=20
> choke=2C I've experienced that before with sessions.

session should be started before any other output unless there is an output=
buffer handler (ob_start)

If I am sure the xreated file is fine=2C zip=2C or whatever=2C even txt=2C =
I've always been able to force a download=2C so if I have not exactly the f=
ile you are using for this download=2C I'll never be able to give you an an=
swer.

old download example function=2C if there any output before obviously it wo=
n't work.
http://www.devpro.it/code/72.html

Regards
=0A=
____________________________________________________________ _____=0A=
Keep your friends updated=97even when you=92re not signed in.=0A=
http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/so=
cial-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL:en -xm:SI_SB_5:092=
010=

--_7beee6bb-7a82-4f02-aa5c-3d8a8f884908_--

RE: Header problem

am 05.10.2009 18:26:29 von Andrea Giammarchi

--_a69f10c2-dc24-4dec-afa7-c27d6e732235_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



> There's a useful function called headers_sent() which checks to see if
> the headers have already been sent to the browser. This might be a good
> place to throw into your code at various points to check and see if
> something is being written which you don't expect.

true=2C check that as well=2C moreover=2C you talked about utf-8=2C well=2C=
if the BOM is automatically added=2C it can cause lots of problems ... sti=
ll=2C only if you sent whatever to the output before the download.
=0A=
____________________________________________________________ _____=0A=
Windows Live: Keep your friends up to date with what you do online.=0A=
http://www.microsoft.com/middleeast/windows/windowslive/see- it-in-action/so=
cial-network-basics.aspx?ocid=3DPID23461::T:WLMTAGL:ON:WL:en -xm:SI_SB_1:092=
010=

--_a69f10c2-dc24-4dec-afa7-c27d6e732235_--

Re: Header problem - "solved"

am 16.10.2009 11:26:15 von Kim Madsen

Andrea Giammarchi wrote on 2009-10-05 18:26:
>
> > There's a useful function called headers_sent() which checks to see if
> > the headers have already been sent to the browser. This might be a good
> > place to throw into your code at various points to check and see if
> > something is being written which you don't expect.
>
> true, check that as well, moreover, you talked about utf-8, well, if the
> BOM is automatically added, it can cause lots of problems ... still,
> only if you sent whatever to the output before the download.

I've tried a bunch of things, including link to index.php and as first
thing check if the request is a zipfile, then throw a zip header,
readfile the file then exit the code. Nothing helped. So I figured it
could be a latin-1 / utf-8 problem and tried to post to a fresh new page
(donwload_zip.php) instead, where I was sure the terminal and Vi was set
to use latin-1, then it worked.

It's still not the ultimate solution as we wanted the zipfile to be
created on the fly in memory in order not to have to delete files
afterwards and to be sure that only allowed users can fetch the files
(of course you can always put the zipfiles outside webscope, but still...)

--
Kind regards
Kim Emax

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Header problem - SOLVED

am 19.10.2009 23:44:57 von Kim Madsen

This has been solved today. Talawa had a similar problem and came up
with a solution to his problem, namely using session_write_close()
before creating the headers. That stunt also solved my problem :-)

--
Kind regards
Kim Emax

Kim Madsen wrote on 2009-10-03 13:30:
> 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&v ersion_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=41e0cd250ca3a40598e2019fd4c8 13cc&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_bro wser=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
> ____________________________________________________________ ________
>


--
Kind regards
Kim Emax - masterminds.dk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php