然而,我尝试了很多方法,但它不起作用
我只需要你的帮助,谢谢高级
function user_ip_exists($ip)
{
// ** Get Connection
open_handler();
$sql = sprintf(" SELECT `ip` FROM `answ` ");
$query = mysql_query($sql);
$database_ip = array();
for ($counter=0; $row = mysql_fetch_assoc($query); $counter++) {
foreach ($row as $key => $value) {
$database_ip[] = $value;
};
}
var_dump($database_ip);
}
// this the above var_dump
array (size=9)
0 => string '' (length=0)
1 => string '' (length=0)
2 => string '' (length=0)
3 => string '' (length=0)
4 => string '' (length=0)
5 => string ',127.0.0.1,127.0.0.1' (length=20) // ip address is separated with ' , '
6 => string '' (length=0)
7 => string '' (length=0)
8 => string '' (length=0)
答案 0 :(得分:0)
您的mysql_*
个功能全部弃用,您必须使用mysqli
或任何其他界面,例如PDO。
要搜索数组,您可以在其上执行另一个循环:
foreach($database_ip as $ip)
{
$parts = explode(",", $ip);
if(in_array($parts, $your_ip)) return true;
}