Forum Moderators: coopster
When a person logs in the following code is used:
<?php
...
<their credentials are verified against the DB>
<if they are a valid user>
...
$_SESSION['ID'] = $row['UNAME'];
$_SESSION['NAME'] = $row['NICK'];
$_SESSION['ACCESS'] = $row['ULVL'];
header('location: index.php');
else
header('location: login.php');
?>
This all works just great. Then when you get to the index page the Welcome Mike appears. <refresh(f5)>. Get redirected to the header page redirect. OR I click the link to go to the admin page, (this needs a few variables from the $_SESSION to allow entrance to the page. Can't go to page, redirects me to login. I changed the isset to echo $_SESSION['ID'] to see if the session variables are persistent and I get the variable not set error(after I leave the index page or refresh).
So the question I guess is:
1- what am I doing wrong
-OR-
2- How do I keep these sessions live until a session_destroy() is called or the browser is closed? I really don't want to use cookies as of yet.
In my experience, all you need to do is call session_start() prior to writing your first variables and then make sure that any page which is going to use the session variables also has a session_start().
Also, if you are using sessions, you are using a cookie.