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
Login Re-direct
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Login Re-direct
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();
}
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Login Re-direct
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.
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.