嗨,我的网站上有 2 个文件config.php
和log_user_ips.php
.
我无法将用户 IP 数据插入我的数据库。
我的数据库包含IPS
表。
配置.php:
<?php require_once("path/to/base/ip_user_logs.php"); fSaveIPUserLog(); ?>
ip_user_logs.php:
<?php
function fSaveIPUserLog() {
return;
$check = mysql_query("SELECT id FROM ips WHERE ip = '".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."' LIMIT 1") or die(mysql_error());
if (mysql_num_rows($check) > 0):
$check_fetched = mysql_fetch_array($check);
$id = (int)$check_fetched['id'];
else:
mysql_query("INSERT INTO ips SET ip = '".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."'") or die(mysql_error());
$id = (int)mysql_insert_id();
endif;
mysql_free_result($check);
mysql_query("UPDATE ips SET
times = times + 1,
host = '".mysql_real_escape_string(gethostbyaddr($_SERVER['REMOTE_ADDR']))."',
agent = '".mysql_real_escape_string($_SERVER['HTTP_USER_AGENT'])."',
script = CONCAT(script, '".mysql_real_escape_string("\n".date('Y-m-d H:i:s').' '.$_SERVER['SCRIPT_NAME'].((count($_GET))? '?'.http_build_query($_GET): ''))."'),
username = IF('".mysql_escape_string($_SESSION[SESSION_PREFIX.'user']['username'])."' != '', '".mysql_escape_string($_SESSION[SESSION_PREFIX.'user']['username'])."', username),
date = NOW()
WHERE id = '$id' LIMIT 1") or die(mysql_error());
return;
}
?>