Connecting Tech Pros Worldwide Help | Site Map

Help -- Headers already sent....

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 11:28 AM
Nabeelah Ali
Guest
 
Posts: n/a
Default Help -- Headers already sent....

session_start()
session_destroy();
echo "<center><font color=red>You are now logged
out!</strong></font></center><br />";
header("Location: index.php");

Can somebody tell me why this bit of code in my logout script doesn't
work? what it's supposed to do is destroy the current session and then
redirect to the home page, but it says that 'Headers already sent' when
i try to do the redirect [header("location: index.php");].


  #2  
Old July 17th, 2005, 11:28 AM
Philip Ronan
Guest
 
Posts: n/a
Default Re: Help -- Headers already sent....

Nabeelah Ali wrote:
[color=blue]
> session_start()
> session_destroy();
> echo "<center><font color=red>You are now logged
> out!</strong></font></center><br />";
> header("Location: index.php");
>
> Can somebody tell me why this bit of code in my logout script doesn't
> work? what it's supposed to do is destroy the current session and then
> redirect to the home page, but it says that 'Headers already sent' when
> i try to do the redirect [header("location: index.php");].
>[/color]

RTFM: <http://www.php.net/session_start>
<http://www.php.net/header>

especially this bit:[color=blue]
> Remember that header() must be called before any actual output is sent, either
> by normal HTML tags, blank lines in a file, or from PHP.[/color]

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/


  #3  
Old July 17th, 2005, 11:28 AM
Anonymous
Guest
 
Posts: n/a
Default Re: Help -- Headers already sent....

Nabeelah Ali wrote:[color=blue]
>
> session_start()
> session_destroy();
> echo "<center><font color=red>You are now logged
> out!</strong></font></center><br />";
> header("Location: index.php");
>
> Can somebody tell me why this bit of code in my logout script doesn't
> work? what it's supposed to do is destroy the current session and then
> redirect to the home page, but it says that 'Headers already sent' when
> i try to do the redirect [header("location: index.php");].[/color]

Headers must be sent before anything else. So either make sure you do
not send anything before the headers or use output buffering. Check
ob_start() and ob_end_flush() in the PHP manual.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.