Re: regarding session

From: Date: Mon, 16 Sep 2002 18:17:16 +0000
Subject: Re: regarding session
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-21787@lists.php.net to get a copy of this message
I use this kind of thing all over the place in my maintenance pages. The index.php is where I have the log in form and code to validate the user (usually against a user database in MySQL). Then all my other pages (such as maint_products.php) will have: <? session_start(); if (!session_is_registered("valid_user")) { header("Location: index.php"); } ?> which forces them back to the login page. I also have a "logged in as $valid_user" displayed at the top of the other pages as a link back to index with a parameter that triggers session_destroy(); to log the user out. Terry On Monday, September 16, 2002, at 12:54 PM, Graeme McLaren wrote:
Smita, you would put something like this in the start of your login validation page: session_start(); // This starts the session $ValidUserID = $UserID; // UserID is the field in your database table, here you're assigning it to $ValidUserID session_register("ValidUserID"); // This function registers the session. On each page thereafter you would use the session_start(); function and then test to see if a valid session has been created by doing something like: if(!session_register("ValidUserID")) {
    echo "Error msg here";
} else {
    echo "This is stuff you see if you are logged in";
} I'm new to all this also, but I've got it working so you shouldn't really have many problems getting sessions to work. Hope this helps you out. Graeme :)


« previous php.db (#21787) next »