PayPal\Core\PPUtils::getLocalIPAddress PHP Метод

getLocalIPAddress() публичный статический Метод

Get the local IP address. The client address is a required request parameter for some API calls
public static getLocalIPAddress ( )
    public static function getLocalIPAddress()
    {
        if (array_key_exists("SERVER_ADDR", $_SERVER) && self::isIPv4($_SERVER['SERVER_ADDR'])) {
            // SERVER_ADDR is available only if we are running the CGI SAPI
            return $_SERVER['SERVER_ADDR'];
        } else {
            if (function_exists("gethostname") && self::isIPv4(gethostbyname(gethostname()))) {
                return gethostbyname(gethostname());
            } else {
                // fallback if nothing works
                return "127.0.0.1";
            }
        }
    }

Usage Example

Пример #1
0
 /**
  * @test
  */
 public function testGetLocalIPAddress()
 {
     $ip = $this->object->getLocalIPAddress();
     $this->assertEquals($ip, filter_var($ip, FILTER_VALIDATE_IP));
     $_SERVER['SERVER_ADDR'] = '127.0.0.1';
     $ip = $this->object->getLocalIPAddress();
     $this->assertEquals($ip, filter_var($ip, FILTER_VALIDATE_IP));
 }
All Usage Examples Of PayPal\Core\PPUtils::getLocalIPAddress