我有这个代码,它可以完全使用MAMP在我的localhost上运行。但是,只要我将其转移到带有在线数据库的实时网站,它就会告诉我,无论如何我都会被禁止。
<?php
include "db/connect.php";
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$userIp = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$userIp = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$userIp = $_SERVER['REMOTE_ADDR'];
}
$ipQuery = mysqli_query($db, "SELECT * FROM banned_ip WHERE ip='".$userIp."'");
$ipCheck = mysqli_num_rows($ipQuery);
if($userIp == $ipCheck) {
}
else{
die ('You are banned from this site!');
}
?>
答案 0 :(得分:0)
if($ipCheck != 0) //banned
else //not banned
您正在计算查询返回的行数。如果一个或多个 返回的行IP地址被禁止。
答案 1 :(得分:0)
$sql = mysql_query ("SELECT ip FROM blocklistIp WHERE ip = '" . mysql_escape_string(getenv('REMOTE_ADDR')) . "' LIMIT 0,1");
if ( mysql_num_rows ($sql) ) {
// code here match found
}
else {
// no match found
}