Advertisement
ujiajah1

get_real_ip()

Feb 6th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.64 KB | None | 0 0
  1. function get_real_ip() {
  2.     $clientip      = isset( $_SERVER['HTTP_CLIENT_IP'] )       && $_SERVER['HTTP_CLIENT_IP']       ?
  3.                      $_SERVER['HTTP_CLIENT_IP']         : false;
  4.     $xforwarderfor = isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && $_SERVER['HTTP_X_FORWARDED_FOR'] ?
  5.                      $_SERVER['HTTP_X_FORWARDED_FOR']   : false;
  6.     $xforwarded    = isset( $_SERVER['HTTP_X_FORWARDED'] )     && $_SERVER['HTTP_X_FORWARDED']     ?
  7.                      $_SERVER['HTTP_X_FORWARDED']       : false;
  8.     $forwardedfor  = isset( $_SERVER['HTTP_FORWARDED_FOR'] )   && $_SERVER['HTTP_FORWARDED_FOR']   ?
  9.                      $_SERVER['HTTP_FORWARDED_FOR']     : false;
  10.     $forwarded     = isset( $_SERVER['HTTP_FORWARDED'] )       && $_SERVER['HTTP_FORWARDED']       ?
  11.                      $_SERVER['HTTP_FORWARDED']         : false;
  12.     $remoteadd     = isset( $_SERVER['REMOTE_ADDR'] )          && $_SERVER['REMOTE_ADDR']          ?
  13.                      $_SERVER['REMOTE_ADDR']            : false;
  14.    
  15.     // Function to get the client ip address
  16.     if ( $clientip          !== false ) {
  17.         $ipaddress = $clientip;
  18.     }
  19.     elseif( $xforwarderfor  !== false ) {
  20.         $ipaddress = $xforwarderfor;
  21.     }
  22.     elseif( $xforwarded     !== false ) {
  23.         $ipaddress = $xforwarded;
  24.     }
  25.     elseif( $forwardedfor   !== false ) {
  26.         $ipaddress = $forwardedfor;
  27.     }
  28.     elseif( $forwarded      !== false ) {
  29.         $ipaddress = $forwarded;
  30.     }
  31.     elseif( $remoteadd      !== false ) {
  32.         $ipaddress = $remoteadd;
  33.     }
  34.     else{
  35.         $ipaddress = false; # unknown
  36.    }
  37.     return $ipaddress;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement