How long left in current session/cookie for WordPress

How would I display the current amount of time left of the cookie/session for a logged in user of WordPress? So for example if the cookie timeout is 24 hours and the user has been logged in for 2 hours then the output would be 22 hours.

Related posts

Leave a Reply

2 comments

  1. WordPress (2.9) stores the log in expiry date (along with other log in details) in a cookie prefixed ‘wordpress_logged_in_’. So, you should be able to do something like the below to display the time until expiry.

    foreach ($_COOKIE as $key => $cookie) {
        if (strpos($key, 'wordpress_logged_in_') === 0) {
            $cookie_array = explode('|', $cookie);
            $expiry_time = $cookie_array[1];
            echo human_time_diff(mktime(), $expiry_time);
            break;
        }
    }