Please help.
I seem to have a major problem with sessions on my setup. No simple
example seems to work. Example below:
page1.php:
<?php
// page1.php
session_start() ;
echo 'Welcome to page #1';
$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat';
$_SESSION['time'] = time();
// Works if session cookie was accepted
echo '<br /><a href="page2.php ">page 2</a>';
// Or maybe pass along the session id, if needed
echo '<br /><a href="page2.php ?' . SID . '">page 2</a>';
?>
Page2.php:
<?php
// page2.php
session_start() ;
echo 'Welcome to page #2<br />';
echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat
echo date('Y m d H:i:s', $_SESSION['time']);
// You may want to use SID here, like we did in page1.php
echo '<br /><a href="page1.php ">page 1</a>';
?>
Output after pressing page2 link:
Welcome to page #2
1970 01 01 00:00:00
page 1
As you may be able to see, page 1 sets the date but page 2 thinks the
variable is not set and the 2 other bits, green and cat are also not
displayed. I have been told that this should work fine. Please tell me
what to look for in my setup?
Thanks
Dan
I seem to have a major problem with sessions on my setup. No simple
example seems to work. Example below:
page1.php:
<?php
// page1.php
session_start() ;
echo 'Welcome to page #1';
$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat';
$_SESSION['time'] = time();
// Works if session cookie was accepted
echo '<br /><a href="page2.php ">page 2</a>';
// Or maybe pass along the session id, if needed
echo '<br /><a href="page2.php ?' . SID . '">page 2</a>';
?>
Page2.php:
<?php
// page2.php
session_start() ;
echo 'Welcome to page #2<br />';
echo $_SESSION['favcolor']; // green
echo $_SESSION['animal']; // cat
echo date('Y m d H:i:s', $_SESSION['time']);
// You may want to use SID here, like we did in page1.php
echo '<br /><a href="page1.php ">page 1</a>';
?>
Output after pressing page2 link:
Welcome to page #2
1970 01 01 00:00:00
page 1
As you may be able to see, page 1 sets the date but page 2 thinks the
variable is not set and the 2 other bits, green and cat are also not
displayed. I have been told that this should work fine. Please tell me
what to look for in my setup?
Thanks
Dan
Comment