| | |
Error here, not there
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 27
Reputation:
Solved Threads: 0
Hello everyone:
I'm a bit frustrated because I'm getting an error on one website but not on another one for the same web page. This tells me there's something different about the PHP settings that is different, but I'm not sure where to begin. This is the error I get:
Warning: Cannot modify header information - headers already sent by
Based on my reading online, it is supposedly common for this error to occur when there is extra white space showing up in the code. I'm not sure that this is my problem because, like I've already mentioned, on one site the code works and the other it doesn't. Here is the code being referenced in the error:
What I'm trying to do is after the order to borrow books has been placed and an email sent telling of the order, I want the session to be destroyed so that there is nothing left in the person's order list. Any ideas what's wrong? Thank you.
I'm a bit frustrated because I'm getting an error on one website but not on another one for the same web page. This tells me there's something different about the PHP settings that is different, but I'm not sure where to begin. This is the error I get:
Warning: Cannot modify header information - headers already sent by
Based on my reading online, it is supposedly common for this error to occur when there is extra white space showing up in the code. I'm not sure that this is my problem because, like I've already mentioned, on one site the code works and the other it doesn't. Here is the code being referenced in the error:
PHP Syntax (Toggle Plain Text)
if(isset($_COOKIE[session_name()])) { setcookie(session_name(), ' ', time()-42000, '/'); } session_destroy(); redirect_to("index_bi.php?order=$name");
•
•
Join Date: Aug 2005
Posts: 158
Reputation:
Solved Threads: 13
You have to make sure, that you definately don't have any html, echo or print before you set the session. Thats because session sends a cookie to the client via the HTTP-header. As soon you have any output, PHP sends the header and the stuff you want the browser to show.
The reason why you don't have the problem on the one server could be, that you have the error-reporting turned off.
The reason why you don't have the problem on the one server could be, that you have the error-reporting turned off.
Make sure that you have no html or other text written with echo before that or any html or text before the
And can easily be fixed by removing the extra space or characters:
I also find it to be a good practice to begin the session right after the
<?php tag. This could be something as simple as a space: PHP Syntax (Toggle Plain Text)
<?php //Notice the space here header("Location: thiswillnotwork.html"); ?>
PHP Syntax (Toggle Plain Text)
<?php //No spaces so the header call should work along with the use of session vars header("Location: thiswillwork.html"); ?>
I also find it to be a good practice to begin the session right after the
<?php tag if I am using it in that script. •
•
Join Date: Jun 2008
Posts: 27
Reputation:
Solved Threads: 0
Thanks for the quick responses. I checked the display errors setting and it's on. And error_reporting is set for 6135. I don't know what this means, but that's the setting for it. And I checked for extra spaces and I don't think there are any. I placed the following on a separate page and I still get the error. It has to be in this script, but I can't see it:
Especially the lines in bold are getting errors.
if(isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000,'/');
}
// 4. Destroy the session
session_destroy();
redirect_to("index_bi.php?order=$name");
Last edited by Pado; May 25th, 2009 at 12:54 pm.
•
•
Join Date: Jun 2008
Posts: 27
Reputation:
Solved Threads: 0
Yeah, it was started first thing. Well, I got it to work, but I'm not sure why. There was some conflict between the lines of code I showed you and code in the header. Here is the header code:
I just cut this header code out of the next web page and it worked fine. But can anyone see the problem here? I would prefer to keep it the way I had it, but will live with it the way it is now if no one sees the problem. Thanks.
PHP Syntax (Toggle Plain Text)
<link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" /> <script language="javascript"> function printpage() { window.print(); } </script> <script language="javascript"> <!-- function confirmPost() { var agree=confirm("Are you sure you want to delete this student?"); if (agree) return true; else return false; } //--> </script> <style> <!-- A{text-decoration:none} --> </style> </head> <div id="header"> <h1>Bohemia Institut</h1> </div> <div id="main">
I'm a bit confused here, is the code above all that you have at the start of your page? No DTD? Do you have 'html' and 'body' tags? The page looks poorly formed (sorry, no offence). Could you print the page, showing the whole code from the beginning to '<div id="header">'.
If you don't reply to your own thread or you can't find the solved link - you're off my Christmas list - permanently! Bah humbug!
•
•
•
•
Hello everyone:
I'm a bit frustrated because I'm getting an error on one website but not on another one for the same web page. This tells me there's something different about the PHP settings that is different, but I'm not sure where to begin. This is the error I get:
Warning: Cannot modify header information - headers already sent by
Based on my reading online, it is supposedly common for this error to occur when there is extra white space showing up in the code. I'm not sure that this is my problem because, like I've already mentioned, on one site the code works and the other it doesn't. Here is the code being referenced in the error:
What I'm trying to do is after the order to borrow books has been placed and an email sent telling of the order, I want the session to be destroyed so that there is nothing left in the person's order list. Any ideas what's wrong? Thank you.PHP Syntax (Toggle Plain Text)
if(isset($_COOKIE[session_name()])) { setcookie(session_name(), ' ', time()-42000, '/'); } session_destroy(); redirect_to("index_bi.php?order=$name");
I was having a similar issue the other day, but my situation was a little different. have you tried ob_start(); and ob_end_flush();?
Try putting ob_start(); athe the start of the page and ob_end_flush(); just after the header("Location: URL")
it will not send anything to the browser until it gets to the on_end_flush so it should work
@ I'm gonna live forever, or die trying.
@ A wise man once told me, in order to understand recursion, you first must understand recursion.
@ A wise man once told me, in order to understand recursion, you first must understand recursion.
•
•
Join Date: Jun 2008
Posts: 27
Reputation:
Solved Threads: 0
This is how my typical web page starts:
The first two sections, the session and connection, are in their own include files. I guess this isn't very good, but I've always worried about the PHP on the page and not the other stuff. Could you enlighten me a bit? Thanks.
PHP Syntax (Toggle Plain Text)
<?php session_start(); function logged_in() { return (isset($_SESSION['user_id'])); } function confirm_logged_in() { if (!logged_in()) { redirect_to("index.php"); } } ?> <?php require("constants.php"); $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); if (!$connection) { die("Database connection failed: " . mysql_error()); } $db_select = mysql_select_db(DB_NAME,$connection); if (!$db_select) { die("Database selection failed: " . mysql_error()); } ?> <?php require_once("includes/functions.php"); ?> <head> <title>Name of Organization</title> <link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" /> <script language="javascript"> function printpage() { window.print(); } </script> <script language="javascript"> <!-- function confirmPost() { var agree=confirm("Are you sure you want to delete this student?"); if (agree) return true; else return false; } //--> </script> <style> <!-- A{text-decoration:none} --> </style> </head> <div id="header"> <h1>Name of Organization</h1> </div> <div id="main">
•
•
•
•
This is how my typical web page starts:
The first two sections, the session and connection, are in their own include files. I guess this isn't very good, but I've always worried about the PHP on the page and not the other stuff. Could you enlighten me a bit? Thanks.PHP Syntax (Toggle Plain Text)
<?php session_start(); function logged_in() { return (isset($_SESSION['user_id'])); } function confirm_logged_in() { if (!logged_in()) { redirect_to("index.php"); } } ?> <?php require("constants.php"); $connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS); if (!$connection) { die("Database connection failed: " . mysql_error()); } $db_select = mysql_select_db(DB_NAME,$connection); if (!$db_select) { die("Database selection failed: " . mysql_error()); } ?> <?php require_once("includes/functions.php"); ?> <head> <title>Name of Organization</title> <link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" /> <script language="javascript"> function printpage() { window.print(); } </script> <script language="javascript"> <!-- function confirmPost() { var agree=confirm("Are you sure you want to delete this student?"); if (agree) return true; else return false; } //--> </script> <style> <!-- A{text-decoration:none} --> </style> </head> <div id="header"> <h1>Name of Organization</h1> </div> <div id="main">
@ I'm gonna live forever, or die trying.
@ A wise man once told me, in order to understand recursion, you first must understand recursion.
@ A wise man once told me, in order to understand recursion, you first must understand recursion.
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Error Loading operating System (Windows NT / 2000 / XP)
- svchost.exe error (Windows NT / 2000 / XP)
- New Hardware Causing Error (Windows NT / 2000 / XP)
- office 2000 install error (Windows NT / 2000 / XP)
- VMWare Unrecoverable Error (*nix Software)
- Error in Wrox Book (Perl)
Other Threads in the PHP Forum
- Previous Thread: How use php array with javascript array
- Next Thread: Help adding required fields on form to email script...
Views: 449 | Replies: 13
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error execution file files folder form forms function functions google href htaccess html htmlspecialchars image include insert integration ip java javascript joomla jquery limit link links login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote replace script search select server session sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






