By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,831 Members | 2,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,831 IT Pros & Developers. It's quick & easy.

Problems with session...

P: n/a
Hi

I am wondering what goes wrong...
I have

session_cache_expire(30);
session_start();

How can I check whether the _last_ session (from e.g. yesterday) has
ended?
My problem is, that once logged in, it remembers it forever. All
$_SESSION variables will stay and will confuse my software next time
they open a browser again, as it can see that the $_SESSION data are
still present...
Is there a way to get to know, that the session has ended, or the
browser has been closed?

WBR
Sonnich

Oct 22 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
jodleren schreef:
Hi
Hi Jodleren,
I am wondering what goes wrong...
I have

session_cache_expire(30);
session_start();

How can I check whether the _last_ session (from e.g. yesterday) has
ended?
You cannot, unless you use own sessionhandlers.

http://nl3.php.net/manual/en/functio...ve-handler.php
My problem is, that once logged in, it remembers it forever. All
$_SESSION variables will stay and will confuse my software next time
they open a browser again, as it can see that the $_SESSION data are
still present...
Possibly this happens because nobody else use that site.
Sessions are destroyed besaed on a random generator.

On the top of my head it is dafault configured with a chance of 1/100
the system will check for stale sessions.
This means that EVERY request to PHP has a 1/100 chance of firing the
session-garbage collection.

Check you php.ini for excact sessting (or use phpinfo()).

Is there a way to get to know, that the session has ended, or the
browser has been closed?
Browser close? No.
Session ended? Yes, with proper session_save_handler (via a db eg).

Regards,
Erwin Moller
>
WBR
Sonnich

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Oct 22 '08 #2

P: n/a
On 22 Oct, 16:33, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
jodleren schreef:
Hi

Hi Jodleren,
I am wondering what goes wrong...
I have
session_cache_expire(30);
session_start();
How can I check whether the _last_ session (from e.g. yesterday) has
ended?

You cannot, unless you use own sessionhandlers.
You can't have a session without using a session handler. You can roll
your own, but there's no need. The default session handler just uses
files - see session.save_path for the directory. To find out when the
session was last used check the mtime (or the atime - but that may
have been updated by backup software etc).
>
Possibly this happens because nobody else use that site.
Sessions are destroyed besaed on a random generator.
Note that the session will be considered closed if its not accessed
after session.gc_maxlifetime, even thought the file may still persist.
Its only cleaned up when the housekeeping job kicks in (based on a
dice throw when any session_start using the same handler is called for
any session).

C.
Oct 23 '08 #3

P: n/a
C. (http://symcbean.blogspot.com/) schreef:
On 22 Oct, 16:33, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
>jodleren schreef:
>>Hi
Hi Jodleren,
>>I am wondering what goes wrong...
I have
session_cache_expire(30);
session_start();
How can I check whether the _last_ session (from e.g. yesterday) has
ended?
You cannot, unless you use own sessionhandlers.

You can't have a session without using a session handler. You can roll
your own, but there's no need. The default session handler just uses
files - see session.save_path for the directory. To find out when the
session was last used check the mtime (or the atime - but that may
have been updated by backup software etc).
>Possibly this happens because nobody else use that site.
Sessions are destroyed besaed on a random generator.

Note that the session will be considered closed if its not accessed
after session.gc_maxlifetime, even thought the file may still persist.
Its only cleaned up when the housekeeping job kicks in (based on a
dice throw when any session_start using the same handler is called for
any session).
That is not true C,
I find my sessions just alive an kicking after a day (or 2 in this case).
My session.gc_maxlifetime = 1440

This is also written in the usercontribution by 'Vextor':
here: http://nl3.php.net/manual/en/ref.session.php (4 april 2008)
It seems that the garbage engine can't delete the expired session
related to the itself. If there is only one session, it won't expire
even if it has expired the gc_maxlifetime set.

It will be necessary another client connecting, starting a different
session, and the garbage collector of this new session will be able to
clean the other expired sessions.
Regards,
Erwin Moller
>
C.

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Oct 24 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.