开发者

IP Address Truncated in MYSQL

开发者 https://www.devze.com 2023-03-27 17:30 出处:网络
I\'m trying to insert the IP address in mysql, but the error message states that the IP is being truncated. The column is an unsigned int(10) in MYSQL 5.5.

I'm trying to insert the IP address in mysql, but the error message states that the IP is being truncated. The column is an unsigned int(10) in MYSQL 5.5.

Error: Data truncated for column 'initial_ip' at row 1

PHP5

//get the IP address
if ( isset($_SERVER["REMOTE_ADDR"]) )    {
    $ip=$_SERVER["REMOTE_ADDR"] . ' ';开发者_StackOverflow
    } else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )    {
    $ip=$_SERVER["HTTP_X_FORWARDED_FOR"] . ' ';
    } else if ( isset($_SERVER["HTTP_CLIENT_IP"]) )    {
    $ip=$_SERVER["HTTP_CLIENT_IP"] . ' ';
}

Thanks for any help


You have to convert the IP to an integer, or save it as string.

BTW: What is that space for that you add to the IP?


You are trying to store something like:

  127.0.0.1

as an integer.. this looks obviously wrong? Change int(10) into varchar(15) and it should work.


Your IP column in your database needs to be of type VARCHAR.

0

精彩评论

暂无评论...
验证码 换一张
取 消