I tried every example of creating a session variable I could find and got the same
results with all of them. The session variables got set on the initial page but
that's the only place I could access them.
I'm certain others new to php have come across this and felt equally foolish after
discovering the solution.
This is a sample login page that starts a session when a user successfully logs in:
<?
$connect...
$sql ...
list($id,$first_name) = mysql_fetch_row($sql);
session_start();
if (!session_is_registered('user_id')) {
session_register('user_id');
$user_id = $id;
session_register('user_name');
$user_name = $first_name;
} else {
echo "<p>Session is set and should now be availalbe on all pages via
a cookie. At least that what I expected.";
}
//Sadly, these vars were only available on this page.
echo "<p>ID: $user_id";
echo "<p>Name: $user_name";
?>
Solution: What I did NOT do, and what is not made very clear in any literature I
came across, is that you need to set the session_start() function at the top of
EVERY page that will be in the session.