tags:

views:

49

answers:

1

Hello,

on my database i've decided to store IP of the visitors who answoers to polls. It's all working, but there is only 2 cases where not only 1 IP is stored, but there is 2 SAME ip for the same visitor

MySQL output (i replaced 2 numbers by XX)

10.188.XX.129, 10.188.XX.129

Here's the script to recieve the IP of the visitor :

    <?php 
 function realip() {
     if (isset($_SERVER)) {
   if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
    $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
   } elseif (isset($_SERVER["HTTP_CLIENT_IP"])) {
    $realip = $_SERVER["HTTP_CLIENT_IP"];
   } else {
    $realip = $_SERVER["REMOTE_ADDR"];
   }

     } else {
   if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
    $realip = getenv( 'HTTP_X_FORWARDED_FOR' );
   } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) {
    $realip = getenv( 'HTTP_CLIENT_IP' );
   } else {
    $realip = getenv( 'REMOTE_ADDR' );
   }
     }
     return $realip;
  }
?>

my question is : 99.9% of the time, only 1 IP is stored on MYSQL. I have 2 cases in mySQL database (example on my post) where 2 IP are stored on 1 row of mySQL : does it means that the visitors were using PROXY ? Thanks

+1  A: 

ahhh well, figured it out at last.
you store IP address not in the int column nor even in varchar(15), but something like varchar(255). So, anything can be stored. So, you store anything but IP address.

well. If you want to store an IP address there is only one available in your script - a $_SERVER["REMOTE_ADDR"] one.

There can be some use of realip() function's result, but it should be used with precautions and knowledge, and - most important part - not instead of IP address, but only in addition to it, as some supplemental info.

Col. Shrapnel
ipClient varchar(39) (in case of ipv6)1. i'll use that function if it's more reliable to figure out IP of visitors / 2. I'm sorry, but i didn't understand your 2. :D
Tristan
@Tristan it's ok, I've removed it anyway. just get rid of this realip function. And you have no worry of ipv6 addresses as it will be very distant future
Col. Shrapnel
distant future ? i already have the possibility by checking an option on my ISP webpage to switch from ipv4 to ipv6
Tristan
@tristan so it worked? And if you switch and then browse to your site, what IP address will it log? Not every option to be trust :)
Col. Shrapnel
unfortunatly, i can't test right now, i've to wait a visitor who have the recquired material to answer, answers ;)
Tristan