php mysql更新IP地址无法正常工作 [英] php mysql updating IP address cannot work right
问题描述
该代码用于更新用户登录的IP地址。当我打印$ sql字符串时,它似乎是正确的,IP地址是1886883852,但更新到mysql后,值为2149463110.我试过将mysql中的数据类型设置为INT(11)bigint(12),都是一样的。
如果我尝试将字符串写为
The code is used to update the IP address user logged in. When I print the $sql string, it seems it is correct, the IP address is 1886883852, but after updated to mysql, the value is 2149463110. I have tried to set the data type in mysql as INT(11) bigint(12), all the same. If I try to write a string as
UPDATE ddns SET LastIP=1886883852, LastUpdate=now() WHERE ID=1
直接使用,不使用任何变量,它可以正常工作。
directly, without using any variable, it works correctly.
真的无法理解。有人可以帮忙吗?
Really cannot understand. Anybody can help?
//get dns
function getIP(){
//check the current ip address registered
//Test if it is a shared client
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$ipaddr=$_SERVER['HTTP_CLIENT_IP'];
//Is it a proxy address
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ipaddr=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ipaddr=$_SERVER['REMOTE_ADDR'];
}
$ipaddr = ip2long($ipaddr);
return $ipaddr;
}
$ipaddr = getIP();
$sql = "UPDATE ddns SET LastIP=$ipaddr, LastUpdate=now() WHERE ID=1";
echo $sql; **//here UPDATE ddns SET LastIP=1886883852, LastUpdate=now() WHERE ID=1**
$result = mysqli_query($dbh,$sql) or die("Query failed:");
**//Here after updated, the value of ipaddr in database is 2149463110**
if ($result)
echo "Update ddns successfully";
else
echo "faild to update ddns";
推荐答案
最后我找到原因。当我使用 Chrome 访问和更新时,数据库将写入2149463110,当我使用 firefox或safari 时,结果将是1886883852.
有什么解释吗?
Finally I find the reason. When I use Chrome to visit and update, the database will write 2149463110, when I use firefox or safari, the result will be 1886883852. Any explanation?
这篇关于php mysql更新IP地址无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!