我有一个PHP代码,该函数用于阻止IP地址。
include ("includes/_db_.php");
$query_ip = mysql_query("SELECT * FROM t_ip_address");
while ($data_ip = mysql_fetch_array($query_ip))
{
$valid_ips = $data_ip['ip_address'];
if (!in_array($_SERVER['REMOTE_ADDR'],$valid_ips))
{
echo '<div class="denied"><img src="images/stop.png"/><span class="titles">Access Denied</span><br><span class="content">Sorry you do not have authorized to access this page.</span></div>
<div class="footer"><a href="../">Back to previous page</a></div>
';
exit();
}
}
但现在面临问题,错误是:警告:in_array()期望参数2为数组,字符串在...中给出
有人有建议吗?
答案 0 :(得分:2)
您最好在数据库中搜索$_SERVER["REMOTE_ADDR"]
并查看是否
它返回任何东西。
$query_ip = mysql_query("SELECT * FROM t_ip_address where ip_address = '".mysql_real_escape_string($_SERVER["REMOTE_ADDR"])."'";
if (!mysql_fetch_array($query_ip)){
echo '<div class="denied"><img src="images/stop.png"/><span class="titles">Access Denied</span><br><span class="content">Sorry you do not have authorized to access this page. </span></div>
<div class="footer"><a href="../">Back to previous page</a></div>
';
exit();
}