Re: Sessions

From: Date: Mon, 26 Apr 2004 16:17:31 +0000
Subject: Re: Sessions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-184670@lists.php.net to get a copy of this message
I usually do something like this. Check if session variable exists, and check if it has a name set. session_start(); if ( !isset($_SESSION['username')) || $_SESSION['username'] == '') { header('Location: login.php'); } > 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 (#184670) next »