Re: Header problem
| From: | Kim Madsen | Date: | Mon, 05 Oct 2009 16:10:57 +0000 |
| Subject: | Re: Header problem | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298606@lists.php.net to get a copy of this message | ||
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:parseHeader must come first (before you output anything) or you get ahtml anderrorI try to better explain ... HTTP works like this: you ask something, you receive something,texts are just one option.Got it so farYour 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 anheaderis an error, everything in output before an header is an error, everything after headers that is not related to that header is anerror,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'swhy Ihave 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 "magicbehaviors" ...you need to download? Well, create a file which aims id to downloadandnothing 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>