/    Sign up×
Community /Pin to ProfileBookmark

Your Session Has Ended!

Hey,

You often see a message that says “You are logged out because your session has ended”

How do you check (in PHP) that the session has ended?

Thanx

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ratcatemeSep 04.2008 — if you go to a site that users session and bookmark the site on a page that requires a login then when you close and open your browser the session is lost(it is a cookie that is deleted when the browser closes)

the best way to check this is say you have $_SESSION['login'] and you set that to true when a user logsin then you can say

<?php
if(isset($_SESSION['login'])){
//display pagee
}else{
//You are logged out because your session has ended
}
?>


Scott.
Copy linkTweet thisAlerts:
@NogDogSep 04.2008 — You could store a timestamp in the session data, and if it is more than X seconds old when a page is accessed, you could show such a message and have them log in again. Or you could just let PHP's session settings delete the session data when it gets past a certain age, and if a user accesses a page with a session cookie but has no session data, then show that message and have them log in again. (See the [url=http://www.php.net/manual/en/session.configuration.php]session runtime config options[/url], in particular the session.gc_probability, session.gc_divisor and session.gc_maxlifetime settings.)
×

Success!

Help @phantom007 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.7,
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,
)...