Try this and pay notice that this script also logs the time the user logged in...
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
session_start();
//files to connect to database
include "db.php";
include "common.php";
if(! isset($POST['userid']) and ! isset($SESSION['userid'])) {
?>
<html>
<head>
<title> Please Log In for Access</title>
<LINK REL="StyleSheet" HREF="css/ics.css" type="text/css">
<script language="JavaScript" src="scripts/.js" type="text/javascript"></script>
</head>
<BODY BGCOLOR="#FFFFFF" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" onload="document.Login.userid.focus();">
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name="Login">
<B>Sales Access</B><br>
<B>Email Address:</B> <input type="Text" name="userid" value="" SIZE="25" CLASS="text"><br>
<B>Password:</B> <input type="password" name="passwd" value="" SIZE="25" CLASS="text"><br>
<INPUT TYPE="submit" NAME="submit" VALUE="Login" CLASS="button" onMouseOver="temp=this.style.color; this.style.color='#ffd700';" onMouseOut="this.style.color=temp;"><br>
</FORM>
</body>
</html>
<?php
exit;
}
if(! isset($SESSION['userid'])) {
$userid = $POST['userid'];
$passwd = $POST['passwd'];
$SESSION['userid'] = $userid;
$SESSION['passwd'] = $passwd;
} else {
$userid = $SESSION['userid'];
$passwd = $_SESSION['passwd'];
}
dbConnect('sales');
$authsql = mysql_query("SELECT * FROM sales_reps WHERE email_address = '$userid' AND password = PASSWORD('$passwd') AND userstatus != '1' ");
if (!$authsql) {
error("A database error occurred while checking your ".
"login details.\nIf this error persists, please ".
"contact the system administrator.".mysql_error()."");
}
if (mysql_num_rows($authsql) == 1) {
$loggedsql = mysql_fetch_array($authsql);
extract ($loggedsql);
if ($loggedin=='0') {
$loginsql = mysql_query("UPDATE sales_reps SET lastlogin=CURRENT_TIMESTAMP, loggedin='1' WHERE email_address = '$userid'");
}
}
if (mysql_num_rows($authsql) == 0) {
unset($SESSION['userid']);
unset($SESSION['passwd']);
session_destroy();
?>
<html>
<head>
<title> Please Log In for Access</title>
<LINK REL="StyleSheet" HREF="css/ics.css" type="text/css">
</SCRIPT>
</head>
<BODY BGCOLOR="#FFFFFF" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" onload="document.Login.userid.focus();">
<form action="<?php echo $SERVER['PHP_SELF'] ?>" method="post" name="Login">
<B>Sales Access</B><br>
Your user ID or password is incorrect, or you are not a registered user on this site.<br>
<B>Email Address:</B><input type="Text" name="userid" value="<?php print $userid; ?>" SIZE="25" CLASS="text"><br>
<B>Password:</B><input type="password" name="passwd" value="" SIZE="25" CLASS="text"><br>
<INPUT TYPE="submit" NAME="submit" VALUE="Login" CLASS="button" onMouseOver="temp=this.style.color; this.style.color='#ffd700';" onMouseOut="this.style.color=temp;"><br>
</FORM>
</body>
</html>
<?php
exit;
}
$SESSION['sales'] = mysql_result($authsql,0,"email_address");
?>