First off, $HTTP_SESSION_VARS is deprected in PHP 4.1 and up, so use $_SESSION instead if you're using a recent version.
You also need to start the sessions using session_start(). Here's an example:
To start the session:Code:session_start(); // you must do this before any output to the browser if (isset($_SESSION['username'])) { echo 'Welcome back, <b>' . $_SESSION['username'] . '</b>.'; } else { echo 'You are not logged in.'; }
Then, until the browser closes, $_SESSION['username'] should be there, as the session ID is stored either in a cookie on the users computer, or passed along in the query string.Code:session_start(); // you must do this before any output to the browser // I'm going to assume you got some login information // from a database and use $user as the database record: if ($user = mysql_fetch_array($users)) { $_SESSION['username'] = $user['name']; } else { echo 'Invalid information'; }
Hope this helped.




Reply With Quote