Loading...
 
Skip to main content

Features / Usability


Increasing Session timeout

Hello,

My boss asked me to change the session timeout because he finds it's too short.
I'm currently trying to find where this time is defined...I really can't find it! I thought it was in the admin section.

      • Damian, I saw another post about this and your answer was to go read about sessions on php.net. I did but I didn't find anything...tried some things but it didn't work.


Also one small question. When I change something in the file php.ini, do I have to restart something or it just takes my changes right away?

Thank you and have a nice day!
Gen

When you change the php.ini you need to restart Apache.

What you are probably experienceing is the CookieMonster problem, not the session problem.

TikiWiki 1.8 uses a lot of cookies, and the browser will only allow 20 maximum. Each submenu item on the menu uses a cookie, not to mention about 4 others for the site setup, plus any others for extra menus and tabs, etc that you use.

So you will probably need to remove the menu options, or redesign without having submenus.

There are better fixes in 1.9, but that code is not stable yet.

--
Damian
TikiWiki Support/Hosting/Development ServicesQuestion ** Christmas Offers Now Available **



What about the parameter called "session.cookie_lifetime" ?

Thanks,
Gen

After some testing, I can say that our timeout is officially 40 minutes...

So anyone knows how to increase it?


Any news on this. I am experiencing the same problem. Tried enabling "remember-me" and also savign sessions to the DB. This is becoming quite a problem, especially for user when editing a wiki, leaving for some reason, coming back and trying to save only to get a response that permission is denied and all editing is lost.

THT. A big issue for me too as a new tiki admin with a new install. Any way to get around this timeout issue when editing? tia, -H

Okay folks, I'm searching everywhere for an answer. On another forum on php, I found a similar "hit" and the winning answer was to place the following snipet of code at the beginning of each page;


// === start session timeout mod =====
session_start();
// set timeout period in seconds (43200 = 12 hours)
$inactive = 43200;
// check to see if $_SESSION'timeout' is set
if(isset($_SESSION'timeout') ) {
$session_life = time() - $_SESSION'timeout';
if($session_life > $inactive)
{ session_destroy(); header("Location: tiki-logout.php"); }
}
$_SESSION'timeout' = time();
// == end of timeout mod =

....So I tried adding that to the tiki-faq_question.php file (so editing a faq text wouldn't time out, hopefully...). No dice. It didn't work.

So now I'm wondering if something like this should be added to the template file for the page instead. This this case /template/tiki-faq_questions.tpl. But after looking at that .tpl file, it doesn't look like it would support the code snippet.

I'm really trying here folks! PLEASE someone take a moment and look into this. Judging by the hit count on this post (over 700), there is a lot of interest in this.

Thanks (again) in advance... -H


The search for the holy grail continues...

http://www.frozenpc.net/s9y/archives/281-The-Quest-to-Conquer-the-PHP-Session-Timeout.htmlQuestion says...

The Quest to Conquer the PHP Session Timeout


PHP sessions are handy little things, however it's a bit tricky to correctly get a custom timeout to work correctly. There are a few key ini settings:
session.gc_maxlifetime -This setting (in seconds) tells the PHP garbage collector how long to keep the session valid. The default is 24 minutes.

session.gc_probability - The probability that the garbage collector will run and clean up old session data. The default value is 1.

session.gc_divisor - The divisor to use with the probability. The default value is 100.

session.save_path - The path for session values to be saved. The default is /tmp, however it is important to change this to a custom folder for the application - especially if you are in a shared hosting enviorment. The garbage collector does not discriminate, and it will delete ANY session data that is older than the set limit, not just ones that correspond to your application.

session.cookie_lifetime - How long to keep the cookie written to the client machine valid. Defaults to 0, which means the cookie will expire at the end of the broswer session (at logout or when closing the broswer).

Now, before you start anything, make sure you have a writable folder setup for your application that you can use to store your session data.

Start your session with something smiliar to:

ini_set('session.gc_maxlifetime', '86400');
ini_set('session.gc_divisor', '1');
ini_set('session.gc_probability', '1');
ini_set('session.cookie_lifetime', '0');
ini_set('session.save_path', /path/to/sessions/myapp);
session_name('myapp');
session_start();

Setting the above configuration well make sure your session files are saveed in a seperate folder, they will expire in 24 hours, and the garbage collector will run everytime session_start is called to cleanup expired sessions.

The problem with alot of other infomormation is that they will suggest setting the cookie_lifetime to be the same as the gc_maxlifetime. The problem with this is that when the cookie value is set, the expiration date is not updated as the user continues to be active in the application. The session data on the server side is updated. So, if this is the case, after the value of cookie_lifetime has expired, even if the session data on the server was just updated, your session will be invalid, and you will be required to login again.

I hope that this post will help someone else in the quest to conquer the php session timeout. It definitely is not very clear, and can be very confusing!

-------


So Okay, all you smart guys, how could the above be integrated into tikiwiki????