Page 1 of 1

Login Re-direct

Posted: Thu Jan 26, 2012 11:13 pm
by amijic
Hi all,

I have created a basic login PHP script that requires a username and password. The script is written using If statements. What I would like to happen is that once a user logs in that he/she be automatically re-directed to a memmebr page. Right now the user needs to click a word/button in order to proceed I would like to skip that step and have them go straight to the member page after they press login.

Basically I am looking to replace the following lines with a re-direct code

if ($username==$dbusername&&$password==$dbpassword)
{
echo "Ckick <a href='Success.php'>here</a> to access members page";
$_SESSION['username']=$dbusername;
}

Thank You

Re: Login Re-direct

Posted: Fri Jan 27, 2012 12:22 am
by social_experiment

Code: Select all

<?php
if ($username==$dbusername&&$password==$dbpassword) {
   session_regenerate_id();
   // set session variables here
   session_write_close();
   header('location: your/page.php');
   exit();   
}
?>
Hth

Re: Login Re-direct

Posted: Fri Jan 27, 2012 1:04 am
by Hitman47
The above will work. You could also use javascript.

The only thing I want to add is try to write your code in the order you want it to actually execute, it can prevent headaches in the future. In your first code snippet you first echo the actual text with the link THEN you set the session variables. Naturally those two operations should be reversed. Just some thoughts, I suppose.