user authentication and conditional redirect

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tgray3
Forum Newbie
Posts: 1
Joined: Wed Feb 19, 2003 1:24 pm
Location: Chicago, IL

user authentication and conditional redirect

Post by tgray3 »

I'm trying to build an extranet for a project. Ideally, there will be a login page which will allow users to enter a username and password (stored in a MySQL database), and, upon successful authentication, the user will be taken to a custom URL (also sotred in database) :?: .

I have done some "Google"-ing on this subject, and the articles I find talk about using header() to achieve this.

As it stands, I have a MySQL database with these fields:

ID
username
password
page - page to send user to upon successful login

Any ideas how to go about this conditional redirect?

Any help would be greatly appreciated.

Thanks!

Tim
ed
Forum Newbie
Posts: 1
Joined: Wed Feb 19, 2003 1:46 pm

Post by ed »

Hi Tim.

It all depend on your implementation.
You have to make some decitions on what will be known to the user
also what will be used as a unique key in MySQL.
Lats say the UserName will have a unique contraint in MYSQL you can then get the account like so..


$sql = "SELECT Password FROM UsersTable WHERE UserName = $_POST[user]"

$result = mysql_query($sql);
$data = mysql_fetch_array($result);
if($_POST[user] == $data[0])
{
//Password matched redirect
// here is the header call for redirection
header("Location:yourCustomPage.php");
exit(); // dont forget exit here !!
}
else
{
// do something here if password was wrong
}

I hope this helps

regards

Ed
Post Reply