Forum Moderators: coopster
$IPAddress = getenv("REMOTE_ADDR");
.... works fine when I access the page from home, but if I access the page from my office (behind 2 NAT devices and a firewall) I get:-
127.255.255.255
No, I'm not hosting the pages at my office... ;)
Any known problems with getenv?
$IPAddress = $_SERVER['REMOTE_ADDR'];
..... does the same.
Thanks,
TJ
So storing it then goes something like this (specifics removed but you'll get the gist:-
$sql = "INSERT INTO db (ip) VALUES('INET_ATON('".$IPAddress."'))";
And retrieved something like:-
$sql = "SELECT INET_NTOA(`ip`) AS ipadd FROM db";
echo $row['ipadd'];
And it's sometimes working, sometimes not...
Any thoughts?
Note: When storing values generated by INET_ATON() [dev.mysql.com], it is recommended that you use anINT UNSIGNEDcolumn. If you use a (signed)INTcolumn, values corresponding to IP addresses for which the first octet is greater than 127 cannot be stored correctly.
Problem is, MySQL is telling me it is storing as an unsigned int, so I suspect I'm misreading something here.
This is the information for that field:-
ip int(11) UNSIGNED
I don't know why it's 11 bytes actually - surely should be 4?
PRECISION.
But creating an INTEGER column (on my version of MySQL at least) will come back with a column defintion of
INT(11). Whereas if you create a column defined as
INT UNSIGNEDand DESCRIBE the table you will see the column defined as
INT(10) UNSIGNED.
Side note:
Both PRECISION and UNSIGNED are MySQL extensions to the standard.
But this has absolutely nothing to do with your issue, mind you ;-)