I have a Dreamweaver login page and I'd like to start recording the last login date/time and IP address for users.
I have created two new columns in the database - lastlogin and lastip.
I think this is the section of the page I need to modify, but can anyone offer some advice?
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=md5($_POST['password']);
$MM_fldUserAuthorization = "type";
$MM_redirectLoginSuccess = "account.php";
$MM_redirectLoginFailed = "index.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_loyalty, $loyalty);
$LoginRS__query=sprintf("SELECT username, password, type FROM users WHERE username=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $loyalty) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'type');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
$ip = $_SERVER["REMOTE_ADDR"];
$update = "UPDATE users SET lastlogin = NOW() , lastip = '$ip' WHERE username = '$loginUsername'";
$result = mysql_query($update) or die (mysql_error());
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
*Update - the above script works