Hi,
Thanks for you reply but I am still a little confused as 'browse' and 'admin are the two values that 'status' can take in the users table.
I only want to let in users that have logged in and their status is set to 'admin' in the table.
Below is the code for the log in page, what should I do?
<?php
//auth_user.php
include "common_db.inc";
$register_script = "register.php";
function auth_user($userid, $userpassword, $status) {
global $default_dbname, $user_tablename;
$link_id = db_connect($default_dbname);
$query = "SELECT username, status FROM $user_tablename
WHERE userid = '$userid'
AND userpassword = password('$userpassword')";
$result = mysql_query($query);
if(!mysql_num_rows($result)) return 0;
else {
$query_data = mysql_fetch_row($result);
return $query_data[0];
}
}
function login_form() {
global $PHP_SELF;
?>
<HEAD>
<TITLE>Login</TITLE>
</HEAD>
<BODY>
<FORM METHOD="POST" ACTION="<? echo $PHP_SELF ?>">
<DIV ALIGN="CENTER"><CENTER>
<H3>Please log in to access the page you requested.</H3>
<TABLE BORDER="1" WIDTH="200" CELLPADDING="2">
<TR>
<TH WIDTH="18%" ALIGN="RIGHT" NOWRAP>ID</TH>
<TD WIDTH="82%" NOWRAP>
<INPUT TYPE="TEXT" NAME="userid" SIZE="8">
</TD>
</TR>
<TR>
<TH WIDTH="18%" ALIGN="RIGHT" NOWRAP>Password</TH>
<TD WIDTH="82%" NOWRAP>
<INPUT TYPE="PASSWORD" NAME="userpassword" SIZE="8">
</TD>
</TR>
<TR>
<TD WIDTH="100%" COLSPAN="2" ALIGN="CENTER" NOWRAP>
<INPUT TYPE="SUBMIT" VALUE="LOGIN" NAME="Submit">
</TD>
</TR>
</TABLE>
</CENTER></DIV>
</FORM>
</BODY>
<?
}
session_start();
if(!isset($userid)) {
login_form();
exit;
}
else {
session_register("userid", "userpassword", "status");
$username = auth_user($userid, $userpassword, $status);
if(!$username) {
session_unregister("userid");
session_unregister("userpassword");
session_unregister("status");
echo "Authorization failed. " .
"You must enter a valid userid and password combo. " .
"Click on the following link to try again.<BR>\n";
echo "<A HREF=\"$PHP_SELF\">Login</A><BR>";
exit;
}
else echo "Welcome, $username!";
}
?>