Get a visitor\'s real IP address.


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

A more reliable way to obtain a visitor's IP address.


Copy this code and paste it in your HTML
  1. <?php
  2. function getRealIp()
  3. {
  4. if (!empty($_SERVER['HTTP_CLIENT_IP'])){
  5. $ip=$_SERVER['HTTP_CLIENT_IP'];
  6. }
  7. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  8. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  9. }
  10. else{
  11. $ip=$_SERVER['REMOTE_ADDR'];
  12. }
  13. return $ip;
  14. }
  15.  
  16. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.