Jump to content

Archived

This topic is now archived and is closed to further replies.

omelette

session not ending

Recommended Posts

Does anyone have any idea why my session doesn't seem to be ending properly when I close my browser?  Could it be to do with the php settings?

I checked the session ID then closed and reopened the browser and the session ID was the same!

Share this post


Link to post
Share on other sites
Have a logout page which will cancel your session.

E.g

[code=php:0]<?php
session_start();

if(!isset($_REQUEST['logmeout'])){
    session_unset();
    session_destroy();
    if(!session_is_registered('username')){
        echo "<center><font color=red><strong>You are now logged out!</strong></font></center><br />";
        echo "<center><strong>Login:</strong></center><br />";
        include 'index.php';
    }
}
?>[/code]

Hope this helps,

dual_alliance

Share this post


Link to post
Share on other sites
logouts work, but you cannot rely on users to logout and you still have the problem of what to do when a browser is closed without logging out.

sessions should be lost when the browser is closed, although they do persist on the server until automatic cleanup gets rid of them.  They can only be reaccessed if there is some memory of the session id, say in a cookie, and specific code to reopen the session.

how are the sessions being started?

try creating a session variable with some value, close your browser, reopen it and see if the stored value is also retained.  

Share this post


Link to post
Share on other sites
Are you closing all instances of the browser

For example, using FireFox
Closing that website does not always end the session (well not straight away)
Whereas closing FireFox (all instances) should

Share this post


Link to post
Share on other sites
I am closing all instances of the browser, I am using Internet Explorer.

I created a session variable and when i close and reopen the browser, the value in the variable is retained.

I am starting the sessions on every page with session_start().

Would the session.cookie_lifetime have anything to do with the problem? It is set to 3600 and i think the default is 0.

Share this post


Link to post
Share on other sites
that must be it

see http://us2.php.net/manual/en/ref.session.php#ini.session.cookie-lifetime

Share this post


Link to post
Share on other sites
Yeah, i think that probably is the problem now, just don't know how to solve it!

I haven't got access to php.ini so need to know if there is another way to change this setting to 0 as i think it may be causing other problems.

Share this post


Link to post
Share on other sites
you can change the parameter for the duration of your script using session_set_cookie_params

see http://us2.php.net/manual/en/function.session-set-cookie-params.php

Share this post


Link to post
Share on other sites
I have tried putting:

session_set_cookie_params(0);

on every page before session_start but this is not having any effect.  Am I using it properly?

Share this post


Link to post
Share on other sites
I've never used it before, but I tested it out and it seems to work.

try this

[code]
$params=session_get_cookie_params();
print_r($params);
[/code]

to see if the operation is actually working.

Share this post


Link to post
Share on other sites
thanks, it seems to work now, not sure why it didn't do anything before.

the only problem is that by setting the cookie parameters to 0, whenever the browser is refreshed, the session is lost so the session doesn't work!  i wanted the session to end only when the browser closes, not when it is refreshed.

any ideas?

Share this post


Link to post
Share on other sites
That doesn't make sense.  I've not had such behavior with refreshes.  Perhaps it is due to the settings on your browser.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.