RE: [PHP] Sessions

From: Date: Mon, 26 Apr 2004 14:15:47 +0000
Subject: RE: [PHP] Sessions
Groups: php.general 
Request: Send a blank email to php-general+get-184649@lists.php.net to get a copy of this message
Hi, As you create a session with session_start, you cannot check !$_SESSION because the session will always exist as soon as you cal session_start. what you could do is to add a value in you session when the user was logged in. For example $_SESSION['login']=true; and yo could also need $_SESSION['username']='John Smith'; To check if the user was logged, check if(isset($_SESSION['login']) && ($_SESSION['login']==true)) then ... else display the login form Maybe you could have a look at the PEAR::Auth package with will handle the login and sessions for you see http://pear.php.net/package/Auth good luck Vincent -----Original Message----- From: H Bartel [mailto:superho@gmx.de] Sent: lundi 26 avril 2004 15:58 To: php-general@lists.php.net Subject: [PHP] Sessions Hi, I have recently started to use and understand Sessions in PHP. Starting and initiating a Session on Login works, but how do or can I check on the following pages, if the user is really logged in? For now I am using the following code, which seems to work: <?php session_start (); if (!$_SESSION) { header("Location: index.php"); // which directs back to login form } ?> Is this a correct way to do so, or is there some better or safer solution to this? Searched the archives as well, but couldn't find an appropriate answer. Thanks in advance for your suggestions & help, Holger -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#184649) next »