Find a Real IP address when Proxy is used


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.