Forums / Setup & design / Automatically logout user after some period of inactivity

Automatically logout user after some period of inactivity

Author Message

Tuomo Syvänperä

Thursday 04 June 2009 4:46:03 am

I want to logout the user after for example 30 minutes, if he/she hasn't done anything. I've been playing around with Session settings in site.ini (ActivityTimeout, SessionTimeout and CookieTimeout).

It seems that I get the user thrown out after 30 minutes if I set the CookieTimeout to 30 minutes, but then the user gets thrown out always, even if he/she has loaded some pages within that 30 minutes.. ActivityTimeout and SessionTimeout doesn't seem to do squat.

André R.

Thursday 04 June 2009 5:42:37 am

It looks like you would have to use ActivityTimout.

The logic in eZUser::isUserLoggedIn( $id ) goes like this:

        $time = time();
        $ini = eZINI::instance();
        $activityTimeout = $ini->variable( 'Session', 'ActivityTimeout' );
        $sessionTimeout = $ini->variable( 'Session', 'SessionTimeout' );
        $time = $time + $sessionTimeout - $activityTimeout;

        $sql = "SELECT DISTINCT user_id
FROM ezsession
WHERE user_id = '" . $userID . "' AND
      expiration_time > '$time'";

Whereas the expiration_time value in the database is set during session writes in eZSession::internalWrite() with happens on every request you make to the server:

$expirationTime = time() + $ini->variable( 'Session', 'SessionTimeout' );

What version are you on?

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Tuomo Syvänperä

Thursday 04 June 2009 10:49:41 pm

Currently I'm on version 4.1.1. I did notice the two functions you mentioned (isUserLoggedIn and internalWrite), but the strange thing is, that they don't seem to get called when the user loads a page. I added a die() to both of those functions and neither gets triggered.

I don' t know if it matters, but currently I also have RequireUserLogin=true in site.ini.

André R.

Friday 05 June 2009 1:19:00 am

internalWrite is normally called after the page request, so there is no supries it doesn't stop the page, isUserLoggedIn on the other hand.. I'll try to look into it.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Tuomo Syvänperä

Tuesday 23 June 2009 3:32:33 am

Any new info about this? Still unable to solve this problem.

André R.

Tuesday 23 June 2009 5:55:55 am

Hi!

I have reproduced your issue and I think SessionTimeout setting is broken so I have created an issue for it where you can add more comments if you want:
http://issues.ez.no/IssueView.php?Id=15093&activeItem=1

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

André R.

Friday 21 August 2009 3:09:55 am

I must have been blind, expired sessions are removed by the gc (garbage collect) code.
This runs normally every 1000 request, as specified in php.ini session settings, however debian based linux distroes breaks this and have their own gc handling that is incomparable with eZ Publish(as in sessions aren't removed at all).

So see above linked issue, there you'll find a bin script witch you can use to manually (or automatically using cronjob) use to remove expired sessions.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Alex Yes

Monday 30 November 2009 9:33:27 am

Not only debian based linux distroes break this. It is also not working on any website which does have less than 1000 page-impressions within the specified SessionTimeOut-Value.

Kirill V

Wednesday 03 November 2010 3:10:35 pm

"

Not only debian based linux distroes break this. It is also not working on any website which does have less than 1000 page-impressions within the specified SessionTimeOut-Value.

"

Gentlemen -

A newbie question - are ActivityTimeout and SessionTimeout related in any way?

ActivityTimeout seems to be intended to log the user out after certain inactivity period, and SessionTimeout just cleans up sessions, i.e. they do similar but different things.

I am running ezPublish 4.2 on Centos, and so far haven't been able to reliably time out users after a certain period.

If it matters - the 'save_path" setting in php.ini is commented out.

Anybody knows how to make it work?

Thanks much,

Kirill

Gaetano Giunta

Thursday 04 November 2010 1:47:51 am

Afair, ActivityTimeout does not log the user out after a given inactivity period. It is in fact little used - you can see its results in the Admin Interface, where the list of sessions can be filtered by 'active' or 'all'.

It is also used in user management to decide how often the 'user last visited' row in the db is updated, and in fetch functions that return the number of logged in users

Principal Consultant International Business
Member of the Community Project Board

Kirill V

Thursday 04 November 2010 5:57:02 am

"

Afair, ActivityTimeout does not log the user out after a given inactivity period. It is in fact little used - you can see its results in the Admin Interface, where the list of sessions can be filtered by 'active' or 'all'.

It is also used in user management to decide how often the 'user last visited' row in the db is updated, and in fetch functions that return the number of logged in users

"

Thanks for the prompt reply.

So there is no way to log the user out after NN minutes?

Thanks,

Kirill

Gaetano Giunta

Thursday 04 November 2010 8:58:45 am

Change SessionTimeout ?

Principal Consultant International Business
Member of the Community Project Board

Kirill V

Thursday 04 November 2010 11:10:03 am

"

Change SessionTimeout ?

"

It worked!

Thanks mucho,

Kirill

Hans Hansen

Thursday 20 January 2011 9:08:31 am

Hi great post, it was very useful to me:)

http://www.fiskegrej-online.dk

eZ debug

Timing: Jan 18 2025 01:14:48
Script start
Timing: Jan 18 2025 01:14:48
Module start 'content'
Timing: Jan 18 2025 01:14:49
Module end 'content'
Timing: Jan 18 2025 01:14:49
Script end

Main resources:

Total runtime1.1587 sec
Peak memory usage4,096.0000 KB
Database Queries235

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0092 587.9688180.7969
Module start 'content' 0.00920.9771 768.7656828.8047
Module end 'content' 0.98630.1723 1,597.5703357.2734
Script end 1.1586  1,954.8438 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00480.4153210.0002
Check MTime0.00150.1334210.0001
Mysql Total
Database connection0.00100.086010.0010
Mysqli_queries1.036489.44752350.0044
Looping result0.00290.24752330.0000
Template Total1.119996.720.5600
Template load0.00250.214020.0012
Template processing1.117496.440520.5587
Template load and register function0.00020.019610.0002
states
state_id_array0.00190.162610.0019
state_identifier_array0.00190.160520.0009
Override
Cache load0.00240.2093730.0000
Sytem overhead
Fetch class attribute can translate value0.00210.184870.0003
Fetch class attribute name0.00170.1432170.0001
XML
Image XML parsing0.00450.384170.0006
class_abstraction
Instantiating content class attribute0.00000.0041230.0000
General
dbfile0.00740.6427390.0002
String conversion0.00000.000730.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
9content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
14content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
20content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
3content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
2content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 54
 Number of unique templates used: 9

Time used to render debug report: 0.0002 secs