note 76375 added to function.header

From: Date: Thu, 12 Jul 2007 14:30:52 +0000
Subject: note 76375 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-128410@lists.php.net to get a copy of this message
If you are finding that header() is not working for no obvious reason, make use of the headers_sent() function to drill down to the cause of the problem. Consider the following scenario, <?php // Sign out signOut(); // Redirect back to the main page header("Location: http://mysite.com/mainpage"); ?> If for some reason, the header() call to redirect is not working, there won't be any error messages, making it difficult to debug. However, using headers_sent(), you may easily find the source of the problem. <?php // Sign out signOut(); /* * If headers were already sent for some reason, * the upcoming call to header() will not work... */ if(headers_sent($file, $line)){ // ... where were the mysterious headers sent from? echo "Headers were already sent in $file on line $line..."; } // Redirect back to the main page header("Location: http://mysite.com/mainpage"); ?> As the documentation states, "header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP." In the above debugging solution, you will find out exactly where any of these problematic output or blank lines exist. You should then be able to resolve the issues with much more ease than if you hunted for the problems aimlessly. ---- Server IP: 66.207.199.35 Probable Submitter: 216.171.96.174 ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- https://master.php.net/note/edit/76375 Del: integrated -- https://master.php.net/note/delete/76375/integrated Del: useless -- https://master.php.net/note/delete/76375/useless Del: bad code -- https://master.php.net/note/delete/76375/bad+code Del: spam -- https://master.php.net/note/delete/76375/spam Del: non-english -- https://master.php.net/note/delete/76375/non-english Del: in docs -- https://master.php.net/note/delete/76375/in+docs Del: other reasons-- https://master.php.net/note/delete/76375 Reject -- https://master.php.net/note/reject/76375 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128410) next »