- db_update('wfpl_sessions', 'expires', $expires, 'where id=%i', $GLOBALS['session_id']);
+# this is a helper function. See session_new()
+function session_touch() {
+ if(!session_exists()) {
+ return;
+ }
+ # is the session extendable?
+ if ($GLOBALS['wfpl_session']['expires'] < $GLOBALS['wfpl_session']['expires_max']) {
+ # would this extend the session by at least 10%?
+ $now = time();
+ $last_activity = $GLOBALS['wfpl_session']['expires'] - $GLOBALS['wfpl_session']['idle_timeout'];
+ # don't db_update if only a tiny fraction of the idle timeout has passed
+ $db_threshold = ceil(0.1 * $GLOBALS['wfpl_session']['idle_timeout']);
+ if ($now > $last_activity + $db_threshold) {
+ $expires = min(
+ $GLOBALS['wfpl_session']['expires_max'],
+ $now + $GLOBALS['wfpl_session']['idle_timeout']
+ );
+ db_update('wfpl_sessions', 'expires', $expires, 'where id=%i', $GLOBALS['wfpl_session']['id']);
+ $GLOBALS['wfpl_session']['expires'] = $expires;
+ }
+ }