Forum Moderators: coopster

Message Too Old, No Replies

session must not expire before the browser window is closed

         

phparion

7:14 pm on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi,

I am making a website in which i am facing the Session Expiration Problem, i mean, after a certain time interval the session is expired and i have to login again. is there anyway to keep the session alive untill and unless the user closes the browser window himself?

currently i am using php 4.1.1 and functions like

 session_start(), session_register() 

i found two functions in manual

 session.cookie_lifetime 

session.cache_expire

but i am not sure if i can use them to fix my problem.

please help me to solve this.
thanks in advance

coopster

8:05 pm on Mar 2, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm guessing garbage collection is kicking in and doing it's job. Have a look at the session.gc_* directives [php.net].

phparion

8:18 pm on Mar 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i have already studied manual but am not able to fix this, if anyone has done this please tell me how can i keep the session live untill and unless the browser window is closed by the user himself.

thanks

coopster

12:46 am on Mar 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There are two actions you need to take.

First, you need to configure those garbage collection directives. If you don't set that up correctly, the server is going to do it's job, just as you are telling it to, and clean out any sessions based on those directives. It is not going to care one bit about the user's cookie setting. Old session is old session, period.

That brings us to the other side of any session, the client. You need to set the session cookie so that it expires only when the user closes the browser (assuming you are using session cookies). The session.cookie_lifetime [php.net] directive helps you set that up.

phparion

3:38 am on Mar 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Coopster, i am using simple sessions with session_start and session_register etc functions.

i think its garbage collection which is doing the harm. please tell me exactly how to disable grabage collection so that it doesnt affect sessions keeping in mind that i am not working on my local pc but online server.

thanks in advance

jatar_k

7:13 am on Mar 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you cant disable garbage collection, you can only make it take longer

if you dont have access to the settings coop mentioned then you will have to find another way

phparion

7:00 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am using

ini_set("session.gc_maxlifetime","seconds"); 

by default it has 1440 value, but i am not able to set it in php.ini as when i execute this script on my pc then i check it in php.ini but it remains the same as 1440. I think if i can do it with online installation too with ini_set, because it will make changes related to my script life time i.e when my script will be terminated the changes will be redone.

any idea why it is not writing the value i mention in ini_set function above?

jatar_k

7:02 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



from the manual
[php.net...]

Sets the value of the given configuration option. Returns the old value on success, FALSE on failure. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

phparion

7:32 pm on Mar 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



thanks,

ini_set("session.gc_maxlifetime","3600"); 

worked for me.