Re: Problem Using Sessions. .. .
| From: | Patel, Aman | Date: | Thu, 05 May 2005 14:55:23 +0000 |
| Subject: | Re: Problem Using Sessions. .. . | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-39381@lists.php.net to get a copy of this message | ||
Shawn Singh wrote:
that was very helpful...Thank you. One question I have is that I want to ensure that my admin page cannot get accessed unless a variable that was registered upon a successful login has been passed into the session...what can I do to ensure this?There are several ways to do this. The simplest way is to authenticate once and store a authentication flag in the session. You can set this authentication flag to true if the log-in was sucesfull. On the administration page, you an just access the flag to see if the user is permitted (i.e. logged on). You can do this using the $_SESSION super global, something like this: (pseudo php code) login.php ... if ( authentication sucessfull ) /* username/password matched*/ { $_SESSION['auth'] = true; // redirect to admin page } else { Display login page with error. } ... admin.php ... if ( $_SESSION['auth'] ) { Show administration page. } else { Display login page with error. } ... ----- NB: Make sure you use Header() redirects BEFORE your scripts prints anything. Otherwise you'll keep getting the warning/error "Warning: Cannot modify header information ..."