SESSION variable problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sleepydad
Forum Commoner
Posts: 75
Joined: Thu Feb 21, 2008 2:16 pm

SESSION variable problem

Post by sleepydad »

I have a multipage site with an initial page for login. The login page is basic with two input fields: one for username the other for password. The following page validates the input and displays information based on successful login. All straightforward to this point. If the username and password validation are successful, I create a SESSION variable to allow access the the remaining pages in the site. The initial SESSION variable is created this way

Code: Select all

 
$_SESSION['password']=md5(trim($_POST['password']));
$_SESSION['username']=$_POST['username'];
 
 if (!isset($_SESSION['loggedin'])) {
    $query="select * from `upass` where `username` = '".$_SESSION['username']."' and `password` = '".$_SESSION['password']."'";
    $result=$db->query($query);
 
if ($result->num_rows<1) {
    echo "<font color='red'>ERROR: Incorrect username or password. Please re-enter:</font><br /><br />
    <form action='login.php' method='post'>
    <input type='submit' value='Retry'>
    </form>";
exit;
} else {
$_SESSION['loggedin']=TRUE;
}
}
////////
Remaining script here to display page if logged in successfully
///////
 
The following pages lead in with:

Code: Select all

 
if (!isset($_SESSION['loggedin'])) {
    echo "<font color='red'>ERROR: You must be logged in to view this page.</font><br /><br />
    <form action='login.php' method='post'>
    <input type='submit' value='Log In'>
    </form>";
exit;
}
////////
Remaining script here to display page if logged in successfully
///////
 
95% of the time the pages work fine, then all of a sudden I'll get the error message requiring me to log in again. I have max_input_time in my php.ini set to 600 so I don't think this is a time out issue. I cannot find a pattern, ie any one page that sends me back to start. Nor have I determined any specific amount of time and/or number of page views that trigger it.

Suggestions?

Thanks in advance -
sleepydad
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: SESSION variable problem

Post by daedalus__ »

max_input_time integer

This sets the maximum time in seconds a script is allowed to parse input data, like POST, GET and file uploads.
sessions last 20 minutes.
Post Reply