I want to destroy session if users are not doing any kind of activity on website. At that time after 5 users automatically redirect on index page. How is it possible? Is possible in php with session handling and for that I have to maintain or update user login time or not..
Step 1: Right click on the desktop, and select Personalize option. Step 2: From the left side panel click on Lock Screen and select Screen saver settings. Step 3: From the drop down bar under screen saver select an option. Step 4: Check the box On resume, display logon screen, change the number to 5 in the Wait box.
It can be done by clicking on the logout button or by destroying that session after a fixed time. By default the expiry time of any particular session that is created is 1440 secs i.e. (24*60) i.e. 24 minutes. But in some cases, we need to change the default time accordingly.
Basically, we have to store both the Username and the Password in the user's browser as cookies. Then every time the page loads the session variable will be set. Hence the user can log in without having to enter the Username and Password again until the life of that cookie expires.
This is relatively easy to achive with this small snippet here:
if(time() - $_SESSION['timestamp'] > 900) { //subtract new timestamp from the old one echo"<script>alert('15 Minutes over!');</script>"; unset($_SESSION['username'], $_SESSION['password'], $_SESSION['timestamp']); $_SESSION['logged_in'] = false; header("Location: " . index.php); //redirect to index.php exit; } else { $_SESSION['timestamp'] = time(); //set new timestamp }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With