Jump to content


Photo

session not ending


  • Please log in to reply
11 replies to this topic

#1 omelette

omelette
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 09 August 2006 - 05:08 PM

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!

#2 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 09 August 2006 - 05:17 PM

Have a logout page which will cancel your session.

E.g

<?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';
    }
}
?>

Hope this helps,

dual_alliance

#3 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 09 August 2006 - 05:19 PM

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.  

#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 09 August 2006 - 05:38 PM

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
Tell me the problem, I will try tell you the solution

#5 omelette

omelette
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 09 August 2006 - 05:53 PM

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.

#6 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 09 August 2006 - 06:22 PM

that must be it

see http://us2.php.net/m...cookie-lifetime



#7 omelette

omelette
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 09 August 2006 - 09:20 PM

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.

#8 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 09 August 2006 - 09:32 PM

you can change the parameter for the duration of your script using session_set_cookie_params

see http://us2.php.net/m...okie-params.php

#9 omelette

omelette
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 09 August 2006 - 09:38 PM

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?

#10 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 10 August 2006 - 01:45 AM

I've never used it before, but I tested it out and it seems to work.

try this

$params=session_get_cookie_params();
print_r($params); 

to see if the operation is actually working.

#11 omelette

omelette
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 10 August 2006 - 08:19 AM

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?

#12 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 11 August 2006 - 02:35 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users