WordPress.org

Ready to get started?Download WordPress

Forums

iThemes Security (formerly Better WP Security)
Obtain the correct public IP address (2 posts)

  1. xiaomaoya
    Member
    Posted 1 year ago #

    The original code:
    /inc/secure.php

    /**
    		 * Returns the actual IP address of the user
    		 *
    		 * @return  String The IP address of the user
    		 *
    		 * */
    		function getIp() {
    
    			//Just get the headers if we can or else use the SERVER global
    			if ( function_exists( 'apache_request_headers' ) ) {
    
    				$headers = apache_request_headers(); 
    
    			} else { 
    
    				$headers = $_SERVER;
    
    			}
    
    			//Get the forwarded IP if it exists
    			if ( array_key_exists( 'X-Forwarded-For', $headers ) ) {
    
    				$theIP = $headers['X-Forwarded-For'];
    
    			} else {
    
    				$theIP = $_SERVER['REMOTE_ADDR'];
    
    			}
    
    			return $theIP;
    
    		}

    The above code is not correct to obtain a public IP address(Always:127.0.0.1).So.I found the following code.I hope I do.

    function getIp() {
    
    $onlineip = '';
        if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
            $onlineip = getenv('HTTP_CLIENT_IP');
        } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
            $onlineip = getenv('HTTP_X_FORWARDED_FOR');
        } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
            $onlineip = getenv('REMOTE_ADDR');
        } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
            $onlineip = $_SERVER['REMOTE_ADDR'];
        }
        return $onlineip;
    
    		}

    http://wordpress.org/extend/plugins/better-wp-security/

  2. xiaomaoya
    Member
    Posted 1 year ago #

    also about:Server / Website IP Address
    The original code:
    /inc/admin/content.php

    <li><?php _e( 'Server / Website IP Address', $this->hook ); ?>: <strong><a target="_blank" title="<?php _e( 'Get more information on this address', $this->hook ); ?>" href="http://whois.domaintools.com/<?php echo $_SERVER['SERVER_ADDR']; ?>"><?php echo $_SERVER['SERVER_ADDR']; ?></a></strong></li>

    The Correct code:

    <li><?php _e( 'Server / Website IP Address', $this->hook ); ?>: <strong><a target="_blank" title="<?php _e( 'Get more information on this address', $this->hook ); ?>" href="http://whois.domaintools.com/<?php echo gethostbyname($_SERVER['HTTP_HOST']); ?>"><?php echo gethostbyname($_SERVER['HTTP_HOST']); ?></a></strong></li>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic