[SOLVED] PHP Login Page with MySQL Auth
Posted: Mon May 05, 2008 9:38 am
Hi all,
Hope someone can help.
I want to write a login page that will redirect users to specific pages.
I habe 1 MySQL DB with 2 tables containing users, the idea is that if users in table1 log in they should be redirected to index1 and if users from table2 log in they have to be redirected to index2 and then a special login for the Admin, not in any DB or table due to security - I haven't figured that one out yet.
I've written a normal login page and it works.
I have done something like:
put each table in a while loop to get name and password and set them as $lname1, lpass1, $lname2 and $lpass2
then check the posted name from the Login page:
$name=$_POST['name']
$pass=$_POST['pass']
which I then match to see which page to call i.e.
if ($name == $lname1 && $pass == $lpass1) {
$_SESSION['basic_is_logged_in'] = true;
mysql_query("insert into table1(last_logged_in) values(SYSDATE());
header(location: index1.php);
} elseif {
$_SESSION['basic_is_logged_in'] = true;
mysql_query("insert into table2(last_logged_in) values(SYSDATE()");
header(location: index2.php);
} else {
echo "Incorrect Username or Password";
}
But in my original Login Page I used a mysql_num_rows() to do the authentication but I don't know how or what to implement to make this work.
Can someone please give me some pointers on how to make this work?
Hope someone can help.
I want to write a login page that will redirect users to specific pages.
I habe 1 MySQL DB with 2 tables containing users, the idea is that if users in table1 log in they should be redirected to index1 and if users from table2 log in they have to be redirected to index2 and then a special login for the Admin, not in any DB or table due to security - I haven't figured that one out yet.
I've written a normal login page and it works.
I have done something like:
put each table in a while loop to get name and password and set them as $lname1, lpass1, $lname2 and $lpass2
then check the posted name from the Login page:
$name=$_POST['name']
$pass=$_POST['pass']
which I then match to see which page to call i.e.
if ($name == $lname1 && $pass == $lpass1) {
$_SESSION['basic_is_logged_in'] = true;
mysql_query("insert into table1(last_logged_in) values(SYSDATE());
header(location: index1.php);
} elseif {
$_SESSION['basic_is_logged_in'] = true;
mysql_query("insert into table2(last_logged_in) values(SYSDATE()");
header(location: index2.php);
} else {
echo "Incorrect Username or Password";
}
But in my original Login Page I used a mysql_num_rows() to do the authentication but I don't know how or what to implement to make this work.
Can someone please give me some pointers on how to make this work?