Hi All,

Terminate session on closing the browser/tab. I am designing a site for the internal use of company employees at the client place, which contains some important secured data. Whenever a user logs in, modifies the data and they directly close the browser instead of logout. so the session is not killed as i set the session maximum time as 8 hours which is equivalent to 28800.
session_set_cookie_params('28800');
I am struck with this since last 2 days. I tried many ways after spending a day browsing all forums. But none of them helped me. It would be ok even if it works only in internet explorer.

Please help me as this urgent..

Is there an absolute need for the cookie? Getting rid of the cookie would clear up that problem.

Ok not any particular need for the cookie. But to clear that cookie how can i find/capture that the browser is closed. Is there any way to find that the window is closed. please do let me know if you know any.
Thanku

Is there an absolute need for the cookie? Getting rid of the cookie would clear up that problem.

Not sure about that. Your script would obviously terminate once the browser or tab is closed so how would it know that it was closed? Skipping the cookie and setting your session variables upon login would seem to be the way to go ... the session is destroyed when the user closes the browser.

I use cookies if I want to "remember" the user when they return or sometimes to auto login a user to chat rooms, forums, etc.

OK Thanku for the reply. I am quite new to php so please be a little patient with my small questions. I tried the following code to set the session variables in ini file.

//Set the ini params
ini_set('display_errors', 1);
ini_set('error_reporting', E_ALL ^ E_NOTICE);
ini_set('session.gc_maxlifetime', 10);
ini_set("session.gc_divisor", "1");
ini_set("session.gc_probability", "100");

Even though i set these params. My session is not getting terminated after 10 seconds. So i tried the statement session_set_cookie_params('28800');. On using this it is remembering the session varibales. Even though i close the window, without login credentials user is able to access the site. Once i comment this i am not able to set the maximum life time. with gc_maxlifetime. So please do help me.

Thanku in andvance!

Not sure about that. Your script would obviously terminate once the browser or tab is closed so how would it know that it was closed? Skipping the cookie and setting your session variables upon login would seem to be the way to go ... the session is destroyed when the user closes the browser.

I use cookies if I want to "remember" the user when they return or sometimes to auto login a user to chat rooms, forums, etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.