note 29970 rejected from function.session-start by rioter
| From: | rioter@php.net | Date: | Sun, 02 Mar 2003 20:21:43 +0000 |
| Subject: | note 29970 rejected from function.session-start by rioter | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-44751@lists.php.net to get a copy of this message | ||
When I try to use the session data on another page, i get this warning:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers
already sent (output started at /home/coldatc/public_html/haze/dbd3/index.php:16) in
/home/coldatc/public_html/haze/dbd3/index.php on line 104
The script works, as I can access the hidden features, but I get the ugly warning.
I have saved this page as login.php, and it will happily set the session data and display the hidden
content:
<?php
session_start();
if ($_POST['username'] == 'haze' and
$_POST['password'] == 'foobar')
{ $_SESSION['username'] = "haze";}
?>
<?php if (!$_SESSION['username']): ?>
<form method="post" action="login.php">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="go">
<?php else: ?>
you are logged in as <?php echo $username; ?>.
<br>
<a href="index.php">go back</a> · <a
href="post.php">post news</a> · <a
href="logout.php">log out</a>
<?php endif; ?>
But it's when I come to request the data on the other page that i get the error:
<?php
session_start();
?>
<?php if (!$_SESSION['username']): ?>
<a href="handlelogin.php">Log In</a>
<?php else: ?>
you are logged in as <?php echo $username; ?>.
<br>
<a href="index.php">go back</a> · <a
href="post.php">post news</a> · <a
href="logout.php">log out</a>
<?php endif; ?>
What's wrong? I can't see anything wrong, and I followed it according to the documentation
on the session_start(); function. :S