网站首页 » 笔记 » 访客IP获取类文件

访客IP获取类文件

September 6, 2016 笔记
<?php
/* 获取客户端IP /
function get_client_ip() {
if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
$client_ip = getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
$client_ip = getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
$client_ip = getenv('REMOTE_ADDR');
} elseif(isset($_SERVER[&#39;REMOTE_ADDR&#39;])&nbsp;&amp;&amp;&nbsp;$_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
$client_ip&nbsp;=&nbsp;$_SERVER['REMOTE_ADDR'];
}
$client_ip&nbsp;=&nbsp;addslashes($client_ip);
@preg_match("/[d.]{7,15}/", $client_ip,&nbsp;$ip);
$ip_addr&nbsp;=&nbsp;$ip[0] ? $ip[0] : 'unknown';
unset($ip);
return $ip_addr;
}
function get_domain($url) {
if (preg_match("/^(http://)?(1+)/i", $url,&nbsp;$domain)) {
return $domain[2];
} else {
return false;
}
}
function format_url($url) {
if ($url != "") {
$url_parts&nbsp;=&nbsp;parse_url($url);
$scheme&nbsp;=&nbsp;$url_parts['scheme'];
$host&nbsp;=&nbsp;$url_parts['host'];
$path&nbsp;=&nbsp;$url_parts['path'];
$port&nbsp;=&nbsp;!empty($url_parts['port']) ? ':'.$url_parts['port'] : '';
$url&nbsp;=&nbsp;(!empty($scheme) ? $scheme.&#39;://&#39;.$host : (!empty($host)&nbsp;?&nbsp;&#39;http://&#39;.$host : 'http://';.$path)).$port.'/';
return $url;
}
}
//
echo get_client_ip();
?>
<p><br/></p>

  1. /
Title - Artist
0:00