Posted By

KhanOf21Century on 05/27/14


Tagged

php real ip address proxy


Versions (?)

Find a Real IP address when Proxy is used


 / Published in: PHP
 

URL: http://topgravity.com/find-my-ip-address/

Code is meant to show the real ip address, in case if user is using a proxy. Most of the time $SERVER["REMOTEADDR"] do not work correctly due to the proxy setting of user. It's a nice solution.

  1. <?php
  2. if (!empty($_SERVER["HTTP_CLIENT_IP"]))
  3. {
  4. //check for ip from share internet
  5. $ip = $_SERVER["HTTP_CLIENT_IP"];
  6. }
  7. elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
  8. {
  9. // Check for the Proxy User
  10. $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
  11. }
  12. else
  13. {
  14. $ip = $_SERVER["REMOTE_ADDR"];
  15. }
  16.  
  17. // This will print user's real IP Address
  18. // does't matter if user using proxy or not.
  19. echo $ip;
  20.  
  21. ?>

Report this snippet  

You need to login to post a comment.