Search the Community
Showing results for tags 'logout'.
-
Login works smoothly. $_SESSION['user_id'] is set (I've confirmed that by echoing this at the top of the page as a troubleshooting step). However, once logged in, selecting either logout or change password from the menu successfully re-directs to the correct URL (either logout.php or change_password.php), but (and this confuses me to no end) the content is the content for index.php. The content for logout.php doesn't display, in other words. In addition, after selecting logout, the user_id variable continues to print at the top of the page, which seems to indicate that the logout functions are not executing correctly. I also attempted to unset the $_SESSION['user_id'] before setting the $_SESSION to an empty array in logout.php, to no effect. The page title remains the default, not "Logout", so, even though the URL string is logout.php, the page is obviously still index.php. No errors on the page, and the server error log shows nothing. Hope someone here has some ideas, because I'm out of them.
-
I was hoping that someone might be able to provide a few lines of code that would automatically log the user out after 20 or 30 minutes of inactivity. Maybe the code could be placed in the config.inc.php file so that it gets run frequently? (Note: I am using the "First Site" as created in chapters 1-6 of Larry's book.) Thanks!
- 4 replies
-
- logout
- inactivity
-
(and 1 more)
Tagged with:
-
I built a login page from the model in this book, and for some reason, sometimes when I login it redirects me back to index.php and it doesn't log me in. Other times it logs me in just fine. Any idea what could be causing this? Here is my login page code. <?php $page_title = 'Login to your account'; include ('includes/header.html'); include ('includes/config.inc.php'); if ($_SERVER['REQUEST_METHOD'] == 'POST'){ require (MYSQL); $trimmed = array_map('trim', $_POST); if (!empty($trimmed['Email']) && filter_var($trimmed['Email'], FILTER_VALIDATE_EMAIL)){ $e = mysqli_real_escape_string($dbc, $trimmed['Email']); } else { $e = FALSE; echo '<p class="error">You forgot to enter your email address, or the email you entered is invalid.</p>'; } if (!empty($trimmed['Pass'])){ $p = mysqli_real_escape_string($dbc, $trimmed['Pass']); } else { $p = FALSE; echo '<p class="error">You forgot to enter your password, or the password you entered is invalid.</p>'; } if ($e && $p){ $q = "SELECT UserID, Fname FROM users WHERE (Email='$e' AND Pass=SHA1('$p')) AND Active IS NULL"; $r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br /> Mysql Error:" . mysqli_error($dbc)); if (@mysqli_num_rows($r) == 1){ $_SESSION = mysqli_fetch_array($r, MYSQLI_ASSOC); mysqli_free_result($r); mysqli_close($dbc); $url = BASE_URL . 'index.php'; ob_end_clean(); header("Location: $url"); exit(); } else { echo '<p class="error">Either the username and password you entered do not match those we have on file, or you have not yet activated your account.</p>'; } } else { echo '<p class="error">Please Try Again</p>'; } mysqli_close($dbc); } ?> <div class="text"> <h1>Login</h1> <p>Your browser must allow cookies in order to log in.</p> <form action="login.php" method="post"> <fieldset> <p><b>Email: <input type="text" name="Email" /></b></p> <p><b>Password: <input type="password" name="Pass" /></b></p> <input type="submit" name="submit" value="Login!" /> </fieldset> </form> </div> <? include ('includes/footer.html'); ?>
-
I am on Chapter 18, I created all the files and they seem to be all like it is written in the book, when I logout I can still see the user menu, if I click on one of the user links it takes me back to the index.php (some of the time) page which is great, meaning I am logged out. But why can I still see the Logged in User links even after I click on logout, sometimes when I click on the user links I can even get to the logged in page after I am logged out. I double checked my login and logout pages and they seem the same as in the book. Is this normal??