php mysql更新IP地址无法正常工作

编程入门 行业动态 更新时间:2024-10-21 03:45:02
本文介绍了php mysql更新IP地址无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

该代码用于更新用户登录的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地址无法正常工作

本文发布于:2023-11-01 12:44:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549363.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   地址   工作   php   mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!