Issue regarding PHP $_SESSION variables

scotty2k2

New Member
I have a login form grabbing hashed passwords from a database. If a "submit checking" \[code\]<input type="hidden">\[/code\] is equal to 1 (the sample below will explain this better) then the page content is revealed, if it is not equal to 1 the login form is displayed. The form is as follows:\[code\]<div id="login" style="<?php echo $style ?>"> //$style is by default "visibility:visible;" but will change to "visibility:hidden;" when correct login info is given<p>Log in</p><form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>"><input type="text" id ="username" name="username" value="http://stackoverflow.com/questions/3716057/Username" onfocus="if (this.value =http://stackoverflow.com/questions/3716057/='Username') this.value=''"><input type="password" id="password" name="password" value="http://stackoverflow.com/questions/3716057/passpass" onfocus="if (this.value =http://stackoverflow.com/questions/3716057/='passpass') this.value=''"><br><input type="submit" name="submit" value="http://stackoverflow.com/questions/3716057/Log Ind"><input type="hidden" name="_submit_check" value="http://stackoverflow.com/questions/3716057/1"> //Submit checker. if set, process login information</form></div><p>No user? Make one <a href="http://stackoverflow.com/questions/3716057/register.php">here.</a></p></div>\[/code\]This works great with my PHP sample but there is one little annoying thing... You have to login every simple time you view the page. Therefore I did this in my PHP script:\[code\]<?php session_start(); $db = DB::connect('mysql://username:pass@host/database'); if (DB::isError($db)){ die("Can't connect: " . $db->getMessage()); }$style = "visibility:visible;";$passwordHash = sha1($_POST['password']);$_SESSION['login'] = $_POST['_submit_check']; //This is the submit checker I mentioned before$sql = 'SELECT username FROM user WHERE username = ? AND passwordHash = ?';$result = $db->query($sql, array($_POST['username'], $passwordHash));if ($_SESSION['login'] == 1) { if ($result->numRows() < 1) { echo '<p>Correct your username and password please</p>'; } else { $style = "visibility: hidden;"; echo '<p>This is the page content</p>'; }}?>\[/code\]Shouldn't the fact that I add the $_POST['_submit_check'] value to a $_SESSION[] variable called 'login' make the users only require to login every 24th minute? That's what I want to, but it's not happening...I hope you understand my question, if not, leave a comment about what you don't understand. I had a hard time explaining my thoughts in this question ;)
 
Back
Top