Author: ApPHP Language: php
Description: Get Remote IP Address in PHP Timestamp: 2017-09-13 20:22:13 +0000
View raw paste Reply
  1. <?php          
  2. // source: http://www.apphp.com/index.php?snippet=php-get-remote-ip-address
  3. function getRemoteIPAddress(){
  4.     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
  5.     return $ip;
  6. }
  7.  
  8. /* If your visitor comes from proxy server you have use another function
  9. to get a real IP address: */
  10. function getRealIPAddress(){    
  11.     if(!empty($_SERVER['HTTP_CLIENT_IP'])){
  12.         //check ip from share internet
  13.         $ip = $_SERVER['HTTP_CLIENT_IP'];
  14.     }else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  15.         //to check ip is pass from proxy
  16.         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  17.     }else{
  18.         $ip = $_SERVER['REMOTE_ADDR'];
  19.     }
  20.     return $ip;
  21. }
  22. ?>
  23.  
  24.  
View raw paste Reply