Posted by Colin McKinnon on 01/02/07 23:56
Jeff wrote:
> Hey
>
> I'm using php version 5.2.0
>
> I'm wondering how we can tell if session_start are resuming the current
> session id or if it just created a new session?
>
> I know I could for example do a test like this: $_SESSION["valid_user"] ==
> NULL (not sure about the syntax).. but there must be a better way to
> determine if session_start() starts a new session or not?
>
It's a lot simpler if you only use cookie based sessions. But something
like:
$started_with = ini_get('use_trans_sid') ?
$_GET[session_name()] :
$_COOKIE[session_name()];
// $started with was the the session identifier passed at start up
// of course this doesn't mean it refers to a valid session...
if ($started_with == session_id()) {
// we have resumed an existing session
}
That's rather complicated though - if a session has been started or resumed,
then $_SESSION will be an array (but maybe an empty one).
if (is_array($_SESSION)) {
// a session has been started or resumed
}
HTH
C.
}
Navigation:
[Reply to this message]
|