本文整理汇总了PHP中tep_validate_ip_address函数的典型用法代码示例。如果您正苦于以下问题:PHP tep_validate_ip_address函数的具体用法?PHP tep_validate_ip_address怎么用?PHP tep_validate_ip_address使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了tep_validate_ip_address函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tep_get_ip_address
function tep_get_ip_address()
{
static $_ip_address;
if (!isset($_ip_address)) {
$_ip_address = '0.0.0.0';
$ip_addresses = array();
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
foreach (array_reverse(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])) as $x_ip) {
$x_ip = trim($x_ip);
if (tep_validate_ip_address($x_ip)) {
$ip_addresses[] = $x_ip;
}
}
}
if (isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip_addresses[] = $_SERVER['HTTP_CLIENT_IP'];
}
if (isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && !empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) {
$ip_addresses[] = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
}
if (isset($_SERVER['HTTP_PROXY_USER']) && !empty($_SERVER['HTTP_PROXY_USER'])) {
$ip_addresses[] = $_SERVER['HTTP_PROXY_USER'];
}
if (isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR'])) {
$ip_addresses[] = $_SERVER['REMOTE_ADDR'];
}
foreach ($ip_addresses as $ip) {
if (!empty($ip) && tep_validate_ip_address($ip)) {
$_ip_address = $ip;
break;
}
}
}
return $_ip_address;
}
示例2: tep_get_ip_address
function tep_get_ip_address()
{
global $HTTP_SERVER_VARS;
$ip_address = null;
$ip_addresses = array();
if (isset($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']) && !empty($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'])) {
foreach (array_reverse(explode(',', $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'])) as $x_ip) {
$x_ip = trim($x_ip);
if (tep_validate_ip_address($x_ip)) {
$ip_addresses[] = $x_ip;
}
}
}
if (isset($HTTP_SERVER_VARS['HTTP_CLIENT_IP']) && !empty($HTTP_SERVER_VARS['HTTP_CLIENT_IP'])) {
$ip_addresses[] = $HTTP_SERVER_VARS['HTTP_CLIENT_IP'];
}
if (isset($HTTP_SERVER_VARS['HTTP_X_CLUSTER_CLIENT_IP']) && !empty($HTTP_SERVER_VARS['HTTP_X_CLUSTER_CLIENT_IP'])) {
$ip_addresses[] = $HTTP_SERVER_VARS['HTTP_X_CLUSTER_CLIENT_IP'];
}
if (isset($HTTP_SERVER_VARS['HTTP_PROXY_USER']) && !empty($HTTP_SERVER_VARS['HTTP_PROXY_USER'])) {
$ip_addresses[] = $HTTP_SERVER_VARS['HTTP_PROXY_USER'];
}
$ip_addresses[] = $HTTP_SERVER_VARS['REMOTE_ADDR'];
foreach ($ip_addresses as $ip) {
if (!empty($ip) && tep_validate_ip_address($ip)) {
$ip_address = $ip;
break;
}
}
return $ip_address;
}
示例3: isValidIpAddress
function isValidIpAddress($ip_address)
{
if (function_exists('tep_validate_ip_address')) {
return tep_validate_ip_address($ip_address);
}
if (function_exists('filter_var') && defined('FILTER_VALIDATE_IP')) {
return filter_var($ip_address, FILTER_VALIDATE_IP, array('flags' => FILTER_FLAG_IPV4));
}
if (preg_match('/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/', $ip_address)) {
$parts = explode('.', $ip_address);
foreach ($parts as $ip_parts) {
if (intval($ip_parts) > 255 || intval($ip_parts) < 0) {
return false;
// number is not within 0-255
}
}
return true;
}
return false;
}