当用户通过 MySql 表和 PHP 登录时,我试图创建一个日志,但我的表中没有显示任何内容。我的代码中的其他所有内容都可以正常工作。具体来说,我正在尝试存储访问者的日期、时间、IP、访问者的机器名称和用户名
我在用着
$username = $member['username'];
$ip = $_SERVER[REMOTE_ADDR];
$date = date('Y-m-d H:i:s');
$host = gethostbyaddr($ip);
$query = "INSERT INTO IP_LOG (DateTime, MachineName, IPAddress, Username) VALUES ($date,$host,$ip,$username)";
$result=mysql_query($qry);
要获取信息,请创建查询并记录信息。
整个过程的代码在检查登录是否成功的时候真的依赖这里
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) > 0) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['mem_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['username'];
$_SESSION['SESS_LAST_NAME'] = $member['password'];
$username = $member['username'];
$ip = $_SERVER[REMOTE_ADDR];
$date = date('Y-m-d H:i:s');
$host = gethostbyaddr($ip);
$query = "INSERT INTO IP_LOG (DateTime, MachineName, IPAddress, Username) VALUES ($date,$host,$ip,$username)";
$result=mysql_query($qry);
session_write_close();
header("location: home.php");
//TODO: Log all Information
exit();
}else {
//Login failed
$errmsg_arr[] = 'user name and password not found';
$errflag = true;
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}
}
}
我知道它可以成功验证凭据,但我似乎无法让日志记录工作。