Jump to content

session help


mworkman

Recommended Posts

I am trying to get sessions to work right

Here are my settings:

session.gc_maxlifetime = 60

session.gc_probability = 1

session.gc_divisor = 1

session.cookie_lifetime = 0  (when browser closes)

 

So say I have two php files:

php1.php

session_start();
$_SESSION['var1'] = 'var1';

 

php2.php

session_start();
echo $_SESSION['var1']. '<br>';

 

So if I go to php1 it will set the variable and then I can go to php2 and it will echo the variable.  This works.  But if I don't do anything and then go back to php2 after 60 seconds the variable should no longer exist.  This part is not working.  What do I need to change to get it to work?

Link to comment
Share on other sites

The access time of the current session data file is refreshed on the session_start() statement and garbage collection won't delete the session data file of the session that caused garbage collection to run.

 

You should not rely on the underlying operation of session garbage collection to DO anything, like log people out. You should handle operations like that in your application code.

Link to comment
Share on other sites

heh. the dude is lost.

 

but anyhow.. what PFMaBiSmAd prolly told you is to check if the session has expired and then to unset your var.. you can get the session lifetime using func session_cache_expire...

 

the problem could also occur from cache. setting  session.cookie_lifetime to same as your session could prolly help... try to run it with your cache disabled so you can sort out wether it is a cache related problem or not.

Link to comment
Share on other sites

I see what you mean, I misread your initial post.  As stated, don't rely on the GC to remove your sessions because it's a Probability, which is not a reliable method.

 

Granted, your 1/1 should mean that it cleans it up everytime, but it should not be relied upon to do so.

 

 

 

http://php.net/manual/en/session.configuration.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.