1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to show ip address of visitors ?

Discussion in 'PHP' started by nnconline, Feb 25, 2009.

  1. #1
    who can help me to code php script that show ip address of visitors ?
     
    nnconline, Feb 25, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    <?php echo $_SERVER['REMOTE_ADDR']; ?>
    PHP:
     
    Danltn, Feb 25, 2009 IP
  3. Gonzo4u

    Gonzo4u Well-Known Member

    Messages:
    410
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Ditto :D

    Gonzo
     
    Gonzo4u, Feb 26, 2009 IP
  4. magiatar

    magiatar Active Member

    Messages:
    68
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #4
    A more accurate IP :)
    To detect proxys ...


    
    function getRealIP() {
    	
    	if ($_SERVER ['HTTP_X_FORWARDED_FOR'] != '') {
    		$client_ip = (! empty ( $_SERVER ['REMOTE_ADDR'] )) ? $_SERVER ['REMOTE_ADDR'] : ((! empty ( $_ENV ['REMOTE_ADDR'] )) ? $_ENV ['REMOTE_ADDR'] : "unknown");
    		
    		// Proxies are added at the end of this header
    		// Ip addresses that are "hiding". To locate the actual IP
    		// User begins to look for the beginning to find
    		// Ip address range that is not private. If not
    		// Found none is taken as the value REMOTE_ADDR
    		
    
    		$entries = split ( '[, ]', $_SERVER ['HTTP_X_FORWARDED_FOR'] );
    		
    		reset ( $entries );
    		while ( list ( , $entry ) = each ( $entries ) ) {
    			$entry = trim ( $entry );
    			if (preg_match ( "/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", $entry, $ip_list )) {
    				// http://www.faqs.org/rfcs/rfc1918.html
    				$private_ip = array ('/^0\./', '/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.((1[6-9])|(2[0-9])|(3[0-1]))\..*/', '/^10\..*/' );
    				
    				$found_ip = preg_replace ( $private_ip, $client_ip, $ip_list [1] );
    				
    				if ($client_ip != $found_ip) {
    					$client_ip = $found_ip;
    					break;
    				}
    			}
    		}
    	} else {
    		$client_ip = (! empty ( $_SERVER ['REMOTE_ADDR'] )) ? $_SERVER ['REMOTE_ADDR'] : ((! empty ( $_ENV ['REMOTE_ADDR'] )) ? $_ENV ['REMOTE_ADDR'] : "unknown");
    	}
    	
    	return $client_ip;
    
    }
    
    Code (markup):

    and of course, to show the ip:

    
       <?php echo "IP: ".getRealIP(); ?>
    
    Code (markup):
     
    magiatar, Feb 26, 2009 IP
  5. mz906

    mz906 Peon

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    mz906, Feb 26, 2009 IP
  6. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Has get_browser started reporting IP address recently?
     
    SmallPotatoes, Feb 26, 2009 IP
  7. mz906

    mz906 Peon

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    no it doesn't it shows browser related info, sorry for the confusion, here's a print_r on get_browser:

    
    Array
    (
        [browser_name_regex] => ^mozilla/5\.0 (macintosh; .*; .*mac os x.*; .*; rv:1\.9.*) gecko/.* firefox/3\.0.*$
        [browser_name_pattern] => Mozilla/5.0 (Macintosh; *; *Mac OS X*; *; rv:1.9*) Gecko/* Firefox/3.0*
        [parent] => Firefox 3.0
        [platform] => MacOSX
        [browser] => Firefox
        [version] => 3.0
        [majorver] => 3
        [frames] => 1
        [iframes] => 1
        [tables] => 1
        [cookies] => 1
        [javaapplets] => 1
        [javascript] => 1
        [cssversion] => 2
        [supportscss] => 1
        [minorver] => 0
        [alpha] => 
        [beta] => 
        [win16] => 
        [win32] => 
        [win64] => 
        [backgroundsounds] => 
        [cdf] => 
        [vbscript] => 
        [activexcontrols] => 
        [isbanned] => 
        [ismobiledevice] => 
        [issyndicationreader] => 
        [crawler] => 
        [aol] => 
        [aolversion] => 0
    )
    
    PHP:
     
    mz906, Mar 3, 2009 IP