Authentication Cookie to be extended with every page load
-
I’m trying to change the auth cookies so that they extend with every page load but therefore I’d also set them for a much shorter time, say 15 mins, much like it’s needed for web apps for example (which is how I intend to use the portion of wordpress I’m going to use this for).
Ideally I would want to do this the JS way too to extend the cookie time with every mouse click and keystroke, so if you have ideas in doing so, it’s very much welcome too.
What I tried, the PHP way – the problem with this one is that it logs me out every time I reload the page (added this to
functions.php
) – one of the things I’m a bit unsure about in this code is the arguments ofwp_set_auth_cookie
:/* Renew cookie at every page load */ function renew_wp_cookie() { global $current_user; get_currentuserinfo(); $userinnow = $current_user->user_login; if (is_user_logged_in()) { wp_set_auth_cookie($userinnow, $remember, $secure); } else wp_clear_auth_cookie(); } add_action('init', 'renew_wp_cookie');
On the JS front, I have found following function in one of the .js files provided with my theme – I may make some use of it, not sure yet how:
function setCookie(c_name,value,expiredays) { var exdate = new Date(); exdate.setDate(exdate.getDate() + expiredays); document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString()) + '; path=/'; }
- The topic ‘Authentication Cookie to be extended with every page load’ is closed to new replies.