I am writing a script that gets the visitors IP, removes the dots off it with explode, stores the IP without dots in the database, and then gets it and echoes it.
But, my IP gets really messed up when I store it into the database.
EXAMPLE: My ip is 178.175.35.205 , without dots: 17817535205 , but when gone through MYSQL, I can even see it on PhpMyAdmin, is transformed to 2147483647.
UPDATE: Turns out everything was fine, but I was using INT except for BIGINT. That fixed it.
I am now using ip2long and long2ip.
Do not reinvent the wheel
use
http://php.net/manual/en/function.ip2long.phpandhttp://php.net/manual/en/function.long2ip.phpfunctions to do conversions.
It would also validate it for you
Make sure in db to use
BIGINTto store it.http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html#integer-types