...

View Full Version : Passing value trough a 3rd page?



Peuplarchie
06-30-2007, 06:00 PM
Good day,
I was looking on the web and I can't find what I'm looking for or I don't really understand.

Let take the example of the login script.

The user enter his user ID and password and then if it match redirect to another page. Now, when he click on a link he would then go to that page, how can I verify is user id and password again on the 3rd page and so on ?

I know it's something easy but I'm don't understand this.

Thanks !

Len Whistler
06-30-2007, 06:19 PM
$_SESSION is what you would use.

PappaJohn
06-30-2007, 06:32 PM
Just to expand on what Len said -

You'd use php sessions to track whether the user has logged in. At the top of each of your php pages you'll need:


session_start();


When you verify a successful log-in, set the session variable:


$_SESSION['loggedin'] = true;


Then, for access to each page, you can check if the user has logged in:


If (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true)
{
// allow user to access page
}
else
{
// redirect to login page
}


If you need the user id for each page, you can set that when you verify the log-in:


$_SESSION['userid'] = $user_id;

Peuplarchie
06-30-2007, 07:23 PM
And what if I want multiple user but I can't use db ?

Peuplarchie
06-30-2007, 07:23 PM
Thanks for the explanation and code !

PappaJohn
06-30-2007, 08:06 PM
You're welcome.

If you need to store multiple users and don't have access to a db, you can use a text file. For security the text file should be outside of your document root, and of course, store a hash of the password and not the actual password.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum