好的,所以我需要检查一个 ip_adress 是否已经在我的数据库中,如果我需要更新“访问”行并添加 1。如果它没有退出,那么将 ip_adress 添加到我的数据库中的“ip_adress”行这是我的代码:
<?php include'connect.php';
//Test if it is a shared client
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
//Is it a proxy address
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip=$_SERVER['REMOTE_ADDR'];
}
$ip = ip2long($ip);
$result = mysqli_query($con,"SELECT ip_adress FROM ip_visits");
while($row = mysqli_fetch_array($result))
{
$ip_adress = $row['ip_adress'];
if($ip_adress === $ip){
mysqli_query($con,"UPDATE ip_visits SET ip_adress = ip_adress + 1");
}else{
mysqli_query($con,"INSERT INTO ip_visits (ip_adress) VALUES ('$ip')");
}
}
mysqli_close($con);
?>