Posted by amygdala on 08/20/07 01:16
<Morlaath@gmail.com> schreef in bericht
news:1187570826.109835.85610@w3g2000hsg.googlegroups.com...
> This is the important code from the index page which is causing the
> error:
>
> <?php
> if($_SESSION['logged']) { ?>
> <td class="welcome" ><b>You are logged in as <?php echo
> $_SESSION['username']; ?>.
> <a href="" onclick="//used to have session_destroy() here">Logout</
> a></b></td>
> <?php } else { ?>
> <td class="welcome"><b>You are not logged in. <a
> href="forms/login.php">Login here</a></b></td>
> <?php } ?>
>
Morlaath,
Each page that you want to (re-)use session variables in need to start with:
<?php
session_start();
if($_SESSION['logged']) { ?>
etc...
As a side note, also keep in mind that nothing should be outputted to the
users browser before you call session_start(). Not even whitespace
characters. This is often overlooked by people that have difficulty getting
sessions to work.
The reason is, that sessions (usually) use cookies. Cookies get send to the
browser using HTTP headers. Once PHP has started outputting content, headers
can't be sent anymore.
HTH
[Back to original message]
|