/    Sign up×
Community /Pin to ProfileBookmark

session in Firefox

Hi all..

I have craeted a session variable as follows

[CODE]$_SESSION[‘test’] = “mm”;[/CODE]

as per my knowledge on session it should destroy when the user is closed.

in IE its working as expected.
but in FF when i attempt to close FF it will ask ” whether you want to save your state” I clicked “yes”
and when I try to open FF again it asks to reload previous session I asked to reload previous session, then my application itself reloads and I am able to see the session I had created is still exist.
Same happens when I kill FF session from windows task manager and reload previous session while opening new FF.

Can you tell me why tis happens?
How can I avoid that??

thanks
btb

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@ZnupiFeb 21.2009 — When you choose to restore your session, Firefox does not only restore your tabs. It also restores your session cookies, etc.

If you choose not to restore your session and open the website again, you'll see the session has expired.
Copy linkTweet thisAlerts:
@btbauthorFeb 21.2009 — Hi Thanks for your reply...

Ya you are correct.. When I choose not to restore my session , then it expires...

But its a security bug in my application...if the user opt to restore previous session, since the session is there it will load my application without logging in..I dont want to permit it...

Do you have any other idea to block it...?
Copy linkTweet thisAlerts:
@NogDogFeb 21.2009 — Decrease the amount of time you allow session data to be stored on the [i]host[/i]. One way would be via the various [url=http://us.php.net/manual/en/session.configuration.php#ini.session.gc-probability]session.gc_* configuration settings[/url]. Another would be to add a session variable that gets the current time stamp saved in it, then have you login status check function require a new login if the time is more than X seconds old.
Copy linkTweet thisAlerts:
@btbauthorFeb 21.2009 — Thanks..its a nice one...

but there is a problem, I have another session with some long life time. so I cant change the expire time in host...

I want to set less expire time for this session only....is it possible by coding???

if yes could you plz put some sample coding????
Copy linkTweet thisAlerts:
@NogDogFeb 21.2009 — It's possible if you use a separate directory to store the session data for all scripts using this shorter session time.
[code=php]
<?php
$sessionDirectory = '/path/to/writable/session/directory';
session_save_path($sessionDirectory);
ini_set('session.gc_maxlifetime', 600); // 10 minutes
ini_set('session.gc_probability', 1);
ini_set('session.gc_divisor', 1); // run garbage collector every time
session_start();
[/code]

One potential problem though is that in my experience the GC stuff is run after the rest of the session_start() stuff is executed. So if a user starts a session, does not do anything for more than the maxlifetime, then starts another script, his data will still be there if no other user has accessed a session via the same session start code after the first user's data has expired (causing the garbage collector to be run).

So if this issue is important and you do not expect some fairly high and consistent enough amount of traffic, then the other option of setting a timestamp session value and checking it on each page access would be more reliable. E.g.:
[code=php]
session_start();
$lastAccess = (isset($_SESSION['accessTime'])) ? $_SESSION['accessTime'] : 0;
$timeOutSeconds = 600;
if(time() - $lastAccess > $timeOutSeconds)
{
$_SESSION = array();
header('Location: http://www.example.com/login.php');
exit;
}
$_SESSION['accessTime'] = time();
// . . . rest of script . . .
?>
[/code]
Copy linkTweet thisAlerts:
@btbauthorFeb 22.2009 — Hi NogDog

Thanks dear...

but the problem with the above code is...

suppose user logged in..and after 10 minutes he clicks browser refresh button,

then according to this script the user cant stay in his application, he will be redirected to the location which is provided. I dont want this to be happen.

so I inorder to avoid this i am planning to send an ajax request at every 9 minutes from clinet side to update 'lastaccess' if the user is logged in.


will it work???? or you have any other easy option ????

please let me know... once again thank you for your help so far
Copy linkTweet thisAlerts:
@ZnupiFeb 22.2009 — Yes, it should work. But why do it? If the user leaves his/her browser open for more than 10 minutes it is possible that he/she has left his/her PC, and someone else can access it. If the browser remains open it doesn't mean that the user is still there.

As I said, using Ajax will work. It's your choice whether to implement this or not.
Copy linkTweet thisAlerts:
@btbauthorFeb 23.2009 — hi,

Thanks Znupi for your reply...

I do agree with you..if user left and someone try to access that PC after 10 minutes the session will destroy and that person cannot access it.

But my question is, if the user is still there and he clicks the browser refresh button after 10 minutes, then I dont want to expire his session and he has to continue with his application opened...

thanks

btb
Copy linkTweet thisAlerts:
@ZnupiFeb 23.2009 — You could do it with a Java applet that accesses the user's webcam and while it detects movement it keeps the session but when there is no movement for 1-2 minutes it deletes it. Yes, I am being sarcastic, but it's the only way to [b]really[/b] know if the user is still there.
×

Success!

Help @btb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...