Sessions just not working at all
Posted: Thu Mar 29, 2007 1:56 pm
When I try to create sessions in firefox or IE it won't carry to the next page. If I try these files:
and
which I found in another thread, it does not carry any session info. Cookies ARE enabled. Any ideas?
Andrew Arnott
Code: Select all
<?php
//Session start
session_start();
//Set session vars
if (!isset($_SESSION['username']) && !isset($_SESSION['password']))
{
$_SESSION['username'] = 'testusername';
$_SESSION['password'] = 'testpassword';
}
else
{
echo '<p>You user name is already set to ' . $_SESSION['username'] . '</p>';
echo '<p>And your password is already set to ' . $_SESSION['password'] . '</p>';
}
if (isset($_GET['clear']))
{
// Unset all of the session variables.
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
// Finally, destroy the session.
session_destroy();
echo '<p>Even though you see the information above, the session has already been terminated.
<a href="' . basename($_SERVER['SCRIPT_FILENAME']) . '">Refresh the page</a> and you will see nothing as the page sets the session vars again.</p>';
}
echo '<p><a href="session-test-page2.php">Click here for page 2</a></p>';
echo '<p><a href="?clear=true">Click here to clear the session data</a></p>';
?>Code: Select all
<?php
//Session start
session_start();
//Set session vars
echo '<p>You user name is ' . $_SESSION['username'] . '</p>';
echo '<p>And your password is ' . $_SESSION['password'] . '</p>';
echo '<a href="session-test-page1.php">Click here to go back to page 1</a>';
?>Andrew Arnott