Cannot modify header information - headers already sent

This is a discussion on "Cannot modify header information - headers already sent" within the PHP Forum section. This forum, and the thread "Cannot modify header information - headers already sent are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 7th, 2005, 13:43
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 25
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tim356
Cannot modify header information - headers already sent

I've just knocked up a quick login system using cookies and when I run my logout script I get this error:
Quote:
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\iponder\dev\afs\logout.php:4) in c:\inetpub\wwwroot\iponder\dev\afs\logout.php on line 8

Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\iponder\dev\afs\logout.php:4) in c:\inetpub\wwwroot\iponder\dev\afs\logout.php on line 9
Logged Out
here is my logout script:

Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?PHP

if (isset($_COOKIE['loggedin']))
{
  setcookie ("loggedin", "", time() - 3600);
  setcookie ("mysite_username","");
echo "Logged Out";
} 

$url = "login.htm";
$delay = "2";

echo '<meta http-equiv="refresh" content="'.$delay.';url='.$url.'">';
?>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


</head>

<body>
</body>
</html>
I know it's not real secure, but ignoring that, can anyone explain to me what this error means and how I can fix it?[/quote]
Reply With Quote

  #2 (permalink)  
Old Aug 7th, 2005, 18:42
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
A cookie is sent via HTTP headers. Unfortunately HTTP headers are sent before any page content and you clearly send some HTML before you try to send the cookie.

Most scripts get around this by doing any checks and sending cookies before the HTML, or using template systems which bypass the problem entirely.
Reply With Quote
  #3 (permalink)  
Old Aug 7th, 2005, 22:58
Tim356's Avatar
Reputable Member
Join Date: Nov 2003
Location: Australia
Age: 25
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tim356
Ahhh... I understand now! Thanks Karl, it's fixed.

I will never comment about the donkey again (well...I can't promise that).
Reply With Quote
Reply

Tags
cannot, modify, header, information, headers, already, sent

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Headers alexgeek Search Engine Optimization (SEO) 2 Jul 7th, 2008 09:08
Modify the DOM? gustaf JavaScript Forum 1 Sep 19th, 2007 23:01
3 choices 3 headers saltedm8 Graphics and 3D 12 Jun 24th, 2007 09:26
Cannot modify header information - headers already sent Gee Bee PHP Forum 7 Mar 12th, 2006 17:34
Form headers appearing bold Freddie PHP Forum 1 Dec 20th, 2005 14:26


All times are GMT. The time now is 18:37.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43