On Mon, 2009-10-05 at 18:10 +0200, Kim Madsen wrote: > 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@xxxxxxx > > > To: php-general@xxxxxxxxxxxxx > > > Subject: Re: 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®. > > <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_4:092009> > > 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