|  | Posted by Jψrn Dahl-Stamnes on 03/12/06 10:15 
JΓΈrn Dahl-Stamnes wrote:
 > I use this code to store the IP addresse:
 >
 > <?php
 >   $IP = $_SERVER['REMOTE_ADDR'];
 >   $query = "update mytable set ipaddr=inet_aton('$IP') where <some code>";
 >   mysql_query ($query);
 > ?>
 >
 > When I do a 'select inet_ntoa(ipaddr) from mytable' most of the
 > ip-addesses shows up correctly, but one showed up as "127.255.255.255",
 > which is meaningless. Comparing to the log, the IP-address was 195.x.x.x
 >
 > Is the $_SERVER['REMOTE_ADDR'] safe to use? Can it be something else that
 > the actual source of the http request to my server?
 
 I found the error. The ipaddr was of type "int" but should have been "int
 unsigned" in order to store ip-addresses from 128.0.0.0 and above. So all
 ip-addresses above 127.255.255.255, was stored as 127.255.255.255.
 
 --
 JΓΈrn Dahl-Stamnes
 http://www.dahl-stamnes.net/dahls/
  Navigation: [Reply to this message] |