Forum Moderators: coopster
This is the code that I found at
http://us2.php.net/function.session-start
page1.php:
<?php
// page1.php
session_start();
$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat';
$_SESSION['time'] = time();
echo '<br /><a href="page2.php">page 2</a>';
?>
page2.php
<?php
// page2.php
session_start();echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat
echo date('Y m d H:i:s', $_SESSION['time']);
?>
When I run this code, I get an error says:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/csmajs/lina/.html/test/page2.php:1) in /home/csmajs/lina/.html/test/page2.php on line 3
My first question is, why is the code giving an error? is it because session_start() was used twice?
My second question is, do I have to add session_start() on every page that I want to use $_SESSION['blah'] at?
Any help would be appreciated
Thanks
Opiston