OutcasT Posted May 7, 2014 Posted May 7, 2014 How can I make my game log out someone after some inactivity? Currently if someone goes off the page and returns later, they are still signed in. How can I change that? Also, if they access the page that it logs in to, it comes up but everything is blank, how can I redirect them? Quote
Dayo Posted May 7, 2014 Posted May 7, 2014 (edited) a simple way to do this is with javascript i.e. <script> var redirectAfter = 30; // Mins var redirectTo = 'logout.php'; setTimeout(function () {document.location = redirectTo;}, (redirectAfter*60000)); </script> What this does is on each page load it will start a timer (time depending on the redirectAfter variable), once the timer is completed it will redirect to a page. I have redirected it to logout.php, this should then log the user out and show the login page. You could make a timeout page and redirect it to that but that is up to you. Edited May 7, 2014 by Dayo Quote
OutcasT Posted May 7, 2014 Author Posted May 7, 2014 a simple way to do this is with javascript i.e. <script> var redirectAfter = 30; // Mins var redirectTo = 'logout.php'; setTimeout(function () {document.location = redirectTo;}, (redirectAfter*60000)); </script> What this does is on each page load it will start a timer (time depending on the redirectAfter variable), once the timer is completed it will redirect to a page. I have redirected it to logout.php, this should then log the user out and show the login page. You could make a timeout page and redirect it to that but that is up to you. I will try that but how can I make it so people can access the main page without being logged in. they cant do anything but access it. how can I redirect then back to the login page? Quote
sniko Posted May 7, 2014 Posted May 7, 2014 I will try that but how can I make it so people can access the main page without being logged in. they cant do anything but access it. how can I redirect then back to the login page? [MENTION=70114]OutcasT[/MENTION] can you define what the main page is? Quote
Script47 Posted May 7, 2014 Posted May 7, 2014 (edited) a simple way to do this is with javascript i.e. <script> var redirectAfter = 30; // Mins var redirectTo = 'logout.php'; setTimeout(function () {document.location = redirectTo;}, (redirectAfter*60000)); </script> What this does is on each page load it will start a timer (time depending on the redirectAfter variable), once the timer is completed it will redirect to a page. I have redirected it to logout.php, this should then log the user out and show the login page. You could make a timeout page and redirect it to that but that is up to you. Off Topic Ha! So simple and for all these years I've been wondering how to do it, how did I not think of this. Thanks! :) On Topic session_unset(); session_destroy(); Make sure you have checks on your "main" page or an authentication page which is included in that PHP file. if(!isset($_SESSION['sessionName']) || empty(trim($_SESSION['sessionName'])) || $_SESSION['sessionName'] == "") { // Redirect to login page and give them error. header("refresh:3; url=login.php"); return; } else { // Session is set, redirect to "main" page header("Location: main.php"); return; } Edited May 7, 2014 by Script47 Quote
Dave Posted May 7, 2014 Posted May 7, 2014 There's another solution holding the last activity in a session and then clearing it. Check this out: http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes Quote
OutcasT Posted May 7, 2014 Author Posted May 7, 2014 (edited) [MENTION=65371]sniko[/MENTION] My main page is a page with 3 frames. - One is the players stats (this refreshes to update) - Two is the navigation, where all the pages are linked from - Three is the main page where the action happens Edited May 7, 2014 by OutcasT Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.