Expire the session after some peiod of time by using in php.
1. session_destroy()
2. unset($_SESSION['testvaraible'])
3. setting the time out for this session
1.session_destroy()
if we will call the session_destroy(), it will destroy all the SESSION variable.It is no need any other parameters.
<?php session_destroy(); ?>
2. unset($_SESSION['testvaraible'])
When we will call the unset() ,it will destroyed the particular variable.
Example:
<?php // Destroyed the session variable "testvaraible". unset($_SESSION['testvaraible']); ?>
3. setting the time out for this session
<?php if isset($_SESSION['LAST_MINITUte_ACTIVITY']) &&
(time() - $_SESSION['LAST_MINITUte_ACTIVITY'] > 1800)) { // last request was more than 30 minutes ago session_unset(); // unset $_SESSION variable for the run-time session_destroy(); // destroy session data in storage } // update last activity time stamp $_SESSION['LAST_MINITUte_ACTIVITY'] = time(); /* You can also use an additional time stamp to regenerate the session ID periodically,to avoid attacks on sessions like session fixation: */ if (!isset($_SESSION['CREATED'])) { $_SESSION['CREATED'] = time(); } else if (time() - $_SESSION['CREATED'] > 1800) { // session started more than 30 minutes ago // change session ID for the current session // an invalidate old session ID session_regenerate_id(true); $_SESSION['CREATED'] = time(); // update creation time }
4.session.gc_maxlifetime()
By using php ini_set session.gc_maxlifetime also we will expire the session.
<?php ini_set session.gc_maxlifetime ?>
Related Posts:
1. 413 “Request Entity Too Large” error with uploading a file
2. Difference between cookies and sessions in php
3. How to create a .webp image in PHP
4. How to expire PHP session after a period of time
5. How to resolved when Logged out sessions get restored by back button
6. why javascript contains property is not working in chrome browser
7. what are the differences between json and jsonp
8. Abstract Class in Php
1. 413 “Request Entity Too Large” error with uploading a file
2. Difference between cookies and sessions in php
3. How to create a .webp image in PHP
4. How to expire PHP session after a period of time
5. How to resolved when Logged out sessions get restored by back button
6. why javascript contains property is not working in chrome browser
7. what are the differences between json and jsonp
8. Abstract Class in Php