-2

I have two vps ,to build sshd on my vps_ip1 and install autoproxy plugin in firefox on local machine, to bind some_domain with vps_ip2,and put the read.php on the vps_ip2.

<?php
echo  $_SERVER['REMOTE_ADDR'];
echo  "<br>";
echo  $_SERVER['REQUEST_TIME'];
echo  "<br>";
echo  $_SERVER['HTTP_X_FORWARDED_FOR'];
echo  "<br>";
echo  $_SERVER['HTTP_CLIENT_IP'];
?>  

Now my local ip is ip0, I connect vps_ip1 with ssh and start autoproxy,when to input some_domain/read.php in firefox , to get the fllowing output :

vps_ip1
1426332103

$_SERVER['HTTP_X_FORWARDED_FOR'] and $_SERVER['HTTP_CLIENT_IP'] get nothing about my ip0.
How to get my local ip0 with some php function?

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
showkey
  • 482
  • 42
  • 140
  • 295

3 Answers3

2

You need to read up on proxies and in which way they can function. Especially read the part about anonymous proxies.

In short, depending on the configuration of the proxy server, it might not give the originating IP, to protect the anonymity of the client.

HTTP_X_FORWARDED_FOR only holds whatever data, the proxyserver voluntarily gives you. It might be nothing. It might be the public IP of the client. It might be the local (lan) IP of the client. It might be a comma separated list of preceding/chained proxies with or without the client. It might even be any spoofed ip(s).

In the end, you cannot just trust any proxy server and what it gives you in the HTTP_X_FORWARDED_FOR header, or even if it gives you anything.

So now you need to check the proxy server that you installed on vps_ip1 and disable the anonymous functionality.

nl-x
  • 11,762
  • 7
  • 33
  • 61
1
   <?php
   if (!empty($_SERVER["HTTP_CLIENT_IP"]))
   {
    //check for ip from share internet
    $ip = $_SERVER["HTTP_CLIENT_IP"];
   }
   elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
   {
    // Check for the Proxy User
    $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
   }
   else
   {
    $ip = $_SERVER["REMOTE_ADDR"];
   }

   // This will print user's real IP Address
   // does't matter if user using proxy or not.
   echo $ip;

   ?>
Jameel Grand
  • 2,294
  • 16
  • 32
0

You have to look at the content of $_SERVER array with the command

 print_r($_SERVER);

and find which variable uses your proxy to transmit your local IP.

Depending on your proxy server, it can be many any of the following possibilites : HTTP_X_FORWARDED,HTTP_X_FORWARDED,HTTP_FORWARDED_FOR,HTTP_FORWARDED,HTTP_CLIENT_IP,HTTP_FORWARDED, or anything else.

See the following question for a quick way to retrieve the IP: What is the most accurate way to retrieve a user's correct IP address in PHP?

Community
  • 1
  • 1
Adam
  • 17,838
  • 32
  • 54