本文整理匯總了PHP中Piwik\IP::sanitizeIp方法的典型用法代碼示例。如果您正苦於以下問題:PHP IP::sanitizeIp方法的具體用法?PHP IP::sanitizeIp怎麽用?PHP IP::sanitizeIp使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Piwik\IP
的用法示例。
在下文中一共展示了IP::sanitizeIp方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getHostSanitized
/**
* Returns hostname, without port numbers
*
* @param $host
* @return array
*/
public static function getHostSanitized($host)
{
return IP::sanitizeIp($host);
}
示例2: isLocalUrl
/**
* Returns `true` if the URL points to something on the same host, `false` if otherwise.
*
* @param string $url
* @return bool True if local; false otherwise.
* @api
*/
public static function isLocalUrl($url)
{
if (empty($url)) {
return true;
}
// handle host name mangling
$requestUri = isset($_SERVER['SCRIPT_URI']) ? $_SERVER['SCRIPT_URI'] : '';
$parseRequest = @parse_url($requestUri);
$hosts = array(self::getHost(), self::getCurrentHost());
if (!empty($parseRequest['host'])) {
$hosts[] = $parseRequest['host'];
}
// drop port numbers from hostnames and IP addresses
$hosts = array_map(array('Piwik\\IP', 'sanitizeIp'), $hosts);
$disableHostCheck = Config::getInstance()->General['enable_trusted_host_check'] == 0;
// compare scheme and host
$parsedUrl = @parse_url($url);
$host = IP::sanitizeIp(@$parsedUrl['host']);
return !empty($host) && ($disableHostCheck || in_array($host, $hosts)) && !empty($parsedUrl['scheme']) && in_array($parsedUrl['scheme'], array('http', 'https'));
}