Skip to content

Commit

Permalink
Returns only IPv4 based addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Patel committed Nov 21, 2015
1 parent d20f9af commit e233887
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions lib/PayPal/Core/PPUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,36 @@ public static function array_match_key($map, $key)



/**
* Get the local IP address. The client address is a required
* request parameter for some API calls
*/
public static function getLocalIPAddress()
{
if (array_key_exists("SERVER_ADDR", $_SERVER)) {
// SERVER_ADDR is available only if we are running the CGI SAPI
return $_SERVER['SERVER_ADDR'];

} else {
if (function_exists("gethostname")) {
// gethostname is available only in PHP >= v5.3
return gethostbyname(gethostname());

} else {
// fallback if nothing works
return "127.0.0.1";
}
}
}
/**
* Get the local IP address. The client address is a required
* request parameter for some API calls
*/
public static function getLocalIPAddress()
{
if (array_key_exists("SERVER_ADDR", $_SERVER)) {
// 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";
}
}
}

/**
* Determines if valid IPv4 or not
*
* @param $ip
* @return bool
*/
public static function isIPv4($ip) {
return filter_var($ip, FILTER_VALIDATE_IP , FILTER_FLAG_IPV4);
}

/**
* Convert xml string to an intermediate nested array
Expand Down

0 comments on commit e233887

Please sign in to comment.