How can i check if session id 066efd5a182729d6fdbd43cb3a80adde
exists or not? (I know it existed at some point in the past, but I need to know if it still does or not)
session_exists("066efd5a182729d6fdbd43cb3a80adde")
? "this session exists" : "this session expired/got deleted/whatever";
PS This is not a duplicate of:
- Check if session exists in php because that guy wanted to see if the current request contained a valid cookie session or not (his problem can be solved with
session_status() == PHP_SESSION_NONE
, mine cannot) - PHP if SESSION exists but is null – i don’t even understand what he means by
How I can check in PHP if SESSION exists but is null.
, i certainly don’t want to check if $_SESSION is null.
2
Answers
as long as you're using the php-redis session module, or the default php-built-in
files
session module:usage:
As with any other session ID as well.
Ensure you have no session opened, then set the
session_id($id)
and start the sessionsession_start()
. It returnsfalse
if there is no such session or if there is automatic fallback to a new session (depends on configuration), then you find$_SESSION[]
populated if there is some data associated with that (new) session id.Then decide what you want to do with the previously (non-) existing session, like kill it with fire, unset the cookie etc. (depends on context.)