Connecting Tech Pros Worldwide Help | Site Map

Help -- Headers already sent....

  #1  
Old July 17th, 2005, 12:28 PM
Nabeelah Ali
Guest
 
Posts: n/a
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, 12:28 PM
Philip Ronan
Guest
 
Posts: n/a

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, 12:28 PM
Anonymous
Guest
 
Posts: n/a

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.
Closed Thread