Session

Posted on 16th Feb 2014 by admin

I am having a little trouble with a session. Not sure if it is my browser or what. I know I do not have any trouble logging into forums such at these, so not sure why this is not working.

first the code. Just basic code from php documentation plus some added checks.

Code: <?php
// page1.php

if (session_start()) {
echo "OK";
} else {
echo "FAIL";
}
// echo phpinfo();
// echo getcwd();
echo 'Welcome to page #1';

$_SESSION['favcolor'] = 'green';
$_SESSION['animal'] = 'cat';
$_SESSION['time'] = time();
print_r($_SESSION);
// 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>';
?>
And

Code: <?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']);
print_r($_SESSION);
// You may want to use SID here, like we did in page1.php
echo '<br /><a href="page1.php">page 1</a>';
?>
There is no reason why this should not work. Can someone go to:

http://www.e-sullivan.com/DIITop25/page1.php

and tell me if it works for you? It shows me that the sessions are being started but the variables are not passing between page1.php and page2.php for me.

Other forums