0

I want to check if user session is expired and ask to login again like wp admin do, e.g. if a user is logged into wp admin and after a few times a popup comes up to login again, with a message: "you will not be moved away from this page". How to do this in php?

  • 1
    Possible duplicate of [How do I expire a PHP session after 30 minutes?](http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes) – callmebob Jun 23 '16 at 05:44

2 Answers2

0

Edit htaccess file

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#Session timeout
php_value session.cookie_lifetime 1800
php_value session.gc_maxlifetime 1800
</IfModule>
# END WordPress
Arshid KV
  • 9,631
  • 3
  • 35
  • 36
0

PHP already got default session timeout set, what you will need to do is that when the user clicks on a link inside the admin page check if the user is logged in and if he/she isn't you save the URL they are on (can be done with session) and then send them to the login page. When logging them in you can check if they have a session for it and redirect them there.

Check if logged in function

if(loggedIn == false) {
    $_SESSION['currentpage'] = get_current_url;
    //redirect to login page
}

Login script

//code to login a user in
//when success
if(isset($_SESSION['currentpage'])) {
    //redirect back to that page
}
else {
    //redirect to home page
}
Fyllekanin
  • 274
  • 1
  • 12