Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1.     /**
  2.      * Get current user IP Address.
  3.      * @return string
  4.      */
  5.     function get_ip_address() {
  6.         if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) {
  7.             return $_SERVER['HTTP_X_REAL_IP'];
  8.         } elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
  9.             // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2
  10.             // Make sure we always only send through the first IP in the list which should always be the client IP.
  11.             return (string) self::is_ip_address( trim( current( explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) );
  12.         } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
  13.             return $_SERVER['REMOTE_ADDR'];
  14.         }
  15.         return '';
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement