Sunday, 21 April 2013

PHP - Professional Script for Get Remote IP Address



  1. <?php          
  2. function getRemoteIPAddress(){
  3.     $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
  4.     return $ip;
  5. }
  6.  
  7. /* If your visitor comes from proxy server you have use another function
  8. to get a real IP address: */
  9. function getRealIPAddress(){   
  10.     if(!empty($_SERVER['HTTP_CLIENT_IP'])){
  11.         //check ip from share internet
  12.         $ip = $_SERVER['HTTP_CLIENT_IP'];
  13.     }else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
  14.         //to check ip is pass from proxy
  15.         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  16.     }else{
  17.         $ip = $_SERVER['REMOTE_ADDR'];
  18.     }
  19.     return $ip;
  20. }
  21. ?>

No comments:

Post a Comment