This is a discussion on HEADERS Already sent (NewBie question) within the PHP Language forums, part of the PHP Programming Forums category; Hello again... I was wondering is there any way to check or output in the errors string which file or ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello again... I was wondering is there any way to check or output in the
errors string which file or where in my code the headers have been sent ? I am trying to use this script ************************************************** ***************************************** function redirect($url) { if(!headers_sent()) { header('Location: http://'.$_SERVER['HTTP_HOST'] . dirname($_SERVER 'PHP_SELF']) . '/' . $url); } else { die('Could not redirect; Headers already sent.'); } } ************************************************** ******************************************* But no luck in some redirect attempts. It works in some files but I can't figure out when it doesn't work. bellow is a part of the code that it doesn't work ************************************************** ************************* <? require_once 'http.php'; ?> <====HEre is the Redirection Function <?php require_once('db_conn.php'); ?> <? session_start(); ?><? header("Cache-control: private"); // IE 6 Fix. ?> <? if (isset($_REQUEST['contcat']) && isset($_REQUEST['action'])) { switch ($_REQUEST['contcat']) { case 'content': switch ($_REQUEST['action']) { case 'add_webpage': printf (($_POST['title']) . ($_POST['Contentbody']) . ($_SESSION['user_id'])); if (isset($_POST['title']) and isset($_POST['Contentbody']) and isset($_SESSION['user_id'])) { mysql_select_db($db, $db); $sql = "INSERT INTO bla bla bla"; mysql_query($sql, $db) or die('Could not content'.mysql_error()); } redirect('index.php'); <<<<<================= break; default: break; } default: break; } } ************************************************** ************************* I would really appreciate some help. Thanks Angelos. |
|
|||
|
As the errors say, headers already sent.
This means that you have already tried to send text, or something to the browser, either using an echo, or print statement. Also check your code, to make sure you have NO whitespace outside the PHP tags, otherwise this will cause apache to send the whitespace, therefore removing your ability to set headers. Headers, as the name suggests must be sent BEFORE you can send any data to be displayed. - Ali* "Angelos" <angelos@redcatmedia.net> wrote in message news:d61uaf$nfd$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com... > Hello again... I was wondering is there any way to check or output in the > errors string which file or where in my code the headers have been sent ? > > I am trying to use this script > ************************************************** ***************************************** > function redirect($url) { > if(!headers_sent()) { > header('Location: http://'.$_SERVER['HTTP_HOST'] . > dirname($_SERVER 'PHP_SELF']) . '/' . $url); > } > else { > die('Could not redirect; Headers already sent.'); > } > } > ************************************************** ******************************************* > But no luck in some redirect attempts. It works in some files but I can't > figure out when it doesn't work. > > bellow is a part of the code that it doesn't work > ************************************************** ************************* > <? require_once 'http.php'; ?> <====HEre is the Redirection Function > <?php require_once('db_conn.php'); ?> > <? session_start(); ?><? header("Cache-control: private"); // IE 6 Fix. > ?> > <? > > > if (isset($_REQUEST['contcat']) && isset($_REQUEST['action'])) { > switch ($_REQUEST['contcat']) { > case 'content': > switch ($_REQUEST['action']) { > case 'add_webpage': > printf (($_POST['title']) . ($_POST['Contentbody']) . > ($_SESSION['user_id'])); > if (isset($_POST['title']) and > isset($_POST['Contentbody']) and isset($_SESSION['user_id'])) { > mysql_select_db($db, $db); > $sql = "INSERT INTO bla bla bla"; > mysql_query($sql, $db) or die('Could not > content'.mysql_error()); > } > redirect('index.php'); <<<<<================= > break; > default: > break; > } > default: > break; > } > } > ************************************************** ************************* > I would really appreciate some help. > Thanks Angelos. > |
|
|||
|
*** Angelos wrote/escribió (Fri, 13 May 2005 10:08:18 +0000 (UTC)):
> Hello again... I was wondering is there any way to check or output in the > errors string which file or where in my code the headers have been sent ? This is the error message I get with PHP 4.1.2 when such error happens: Warning: Cannot add header information - headers already sent by (output started at /mnt/webs/Pruebas/www/borrame.php:7) in /mnt/webs/Pruebas/www/borrame.php on line 9 Have you disabled error reporting? Try this: error_reporting(E_ALL); -- -- Álvaro G. Vicario - Burgos, Spain -- http://bits.demogracia.com - Mi sitio sobre programación web -- Don't e-mail me your questions, post them to the group -- |
|
|||
|
>> Hello again... I was wondering is there any way to check or output in the
>> errors string which file or where in my code the headers have been sent ? > > This is the error message I get with PHP 4.1.2 when such error happens: > > Warning: Cannot add header information - headers already sent by (output > started at /mnt/webs/Pruebas/www/borrame.php:7) in > /mnt/webs/Pruebas/www/borrame.php on line 9 > > Have you disabled error reporting? Try this: > > error_reporting(E_ALL); I have enabled the error reporting. And I also have error_reporting = E_ALL which should report my errors as you say above. Although it doesn't work for some reason. The only error that I get is the one that I wrote in my function: function redirect($url) { if(!headers_sent()) { header('Location: http://'.$_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/' . $url); } else { die('Could not redirect; Headers already sent.'); } } |