session_exist() ?? Can this be done?

From: Date: Sun, 04 Apr 2004 18:11:22 +0000
Subject: session_exist() ?? Can this be done?
Groups: php.general 
Request: Send a blank email to php-general+get-182293@lists.php.net to get a copy of this message
Hi, is there any way to know if a site visitor has an existing session without having to first start the session using session_start()? I'm trying to avoid starting a valid session unless the visitor has been authenticated and logged in, so, here's what I do now at the top of every page: session_start() if (!$_SESSION['loggedin']) { session_destroy(); header("Location:/login.php"); // Send to Log-In page. } Is this the most efficient way to do this? I'd prefer to not have to start then immediately destroy the session if it's possible to first know whether a session exists without starting it. I have my site set to store the PHPSESSID in a cookie only (not passed via URL), so, would checking for the existence of $_COOKIE['PHPSESSID'] be a reliable way of doing this? Any other suggestions are appreciated! Monty

« previous php.general (#182293) next »