Best way to get user ip address in php

Here is a function to getting ip using filter of local and lan ip's.

function get_ip()
{
   $list = array( 'REMOTE_ADDR', 'CLIENT_IP', 'HTTP_CLIENT_IP', 
                  'HTTP_PROXY_CONNECTION', 'HTTP_FORWARDED', 'HTTP_X_FORWARDED', 
                  'FORWARDED_FOR_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED_FOR_IP', 
                  'HTTP_X_FORWARDED_FOR', 'FORWARDED', 'X_FORWARDED_FOR', 'FORWARDED_FOR', 
                  'X_FORWARDED', 'HTTP_VIA', 'VIA' );
   foreach ( $list as $v ) {
      if ( isset( $_SERVER[$v] ) )
         return $_SERVER[$v];
      else
         continue;
   }
   return false;
}
 
echo get_ip();

Tags

No tag here.

Recommended pages

Parse a string into separate words...

Parse a string into separate words (array output). function parser($str, $char = ' ') { $str = trim($str); $str = $str . $char; $len = strlen($str); $words = array(); $w = '...

Validate phone number...

Chek if a phone numbers is valid, according to its syntax (should be: "+390523599314"). True if it's valid, False otherwise function is_valid_phone( $phone ) { if ( $phone[0] != "+" ) { ...

SQL escape string function...

Escapes special characters in a string for use in an SQL statement. howewer it check get_magic_quotes_gpc function is enable or no. if true , it strips string from slashes and escaped string from spec...

PHP subwords() Function...

Function subwords, gets words by max num....