Tip: Store IP address as Integer in #MySQL
@admin
Updated July 12, 2013 ● 797 views
Updated July 12, 2013 ● 797 views
Programming
Here's how you store IP addres as integer in MySQL:
To read it as an IP, use to INET_NTOA function in MySQL:
//if shared client
if (!empty($_SERVER['HTTP_CLIENT_IP']))
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
//if proxy address<
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
//convert ip to integer
$ip = ip2long($ip);
To read it as an IP, use to INET_NTOA function in MySQL:
SELECT INET_NTOA(ip) FROM 'user';
3 Comments
Related
More in Programming
▶︎
permalink · reply (0)
permalink · reply (1)
permalink · reply