php REMOTE_ADDR之获取访客IP的代码
程序员文章站
2023-08-29 08:12:22
[/code][code]
<?php
$iipp=$_server["remote_addr"];
echo $iipp;
?>[/code][code]<?php
$user_ip = ($_server["http_via"]) ? $_server["http_x_forwarded_for"] : $_server["remote_addr"];
$user_ip = ($user_ip) ? $user_ip : $_server["remote_addr"];
echo $user_ip;
?>
<?php
function get_real_ip(){
$ip=false;
if(!empty($_server["http_client_ip"])){
$ip = $_server["http_client_ip"];
}
if (!empty($_server['http_x_forwarded_for'])) {
$ips = explode (", ", $_server['http_x_forwarded_for']);
if ($ip) { array_unshift($ips, $ip); $ip = false; }
for ($i = 0; $i < count($ips); $i++) {
if (!eregi ("^(10|172.16|192.168).", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_server['remote_addr']);
}
echo get_real_ip();
?>
<?php
if ($http_server_vars["http_x_forwarded_for"])
{
$ip = $http_server_vars["http_x_forwarded_for"];
}
elseif ($http_server_vars["http_client_ip"])
{
$ip = $http_server_vars["http_client_ip"];
}
elseif ($http_server_vars["remote_addr"])
{
$ip = $http_server_vars["remote_addr"];
}
elseif (getenv("http_x_forwarded_for"))
{
$ip = getenv("http_x_forwarded_for");
}
elseif (getenv("http_client_ip"))
{
$ip = getenv("http_client_ip");
}
elseif (getenv("remote_addr"))
{
$ip = getenv("remote_addr");
}
else
{
$ip = "unknown";
}
echo "你的ip:".$ip ;
?>
<?php
if(getenv('http_client_ip')) {
$onlineip = getenv('http_client_ip');
} elseif(getenv('http_x_forwarded_for')) {
$onlineip = getenv('http_x_forwarded_for');
} elseif(getenv('remote_addr')) {
$onlineip = getenv('remote_addr');
} else {
$onlineip = $http_server_vars['remote_addr'];
}
echo $onlineip;
?>
$iipp=$_server["remote_addr"];
echo $iipp;
?>[/code][code]<?php
$user_ip = ($_server["http_via"]) ? $_server["http_x_forwarded_for"] : $_server["remote_addr"];
$user_ip = ($user_ip) ? $user_ip : $_server["remote_addr"];
echo $user_ip;
?>
<?php
function get_real_ip(){
$ip=false;
if(!empty($_server["http_client_ip"])){
$ip = $_server["http_client_ip"];
}
if (!empty($_server['http_x_forwarded_for'])) {
$ips = explode (", ", $_server['http_x_forwarded_for']);
if ($ip) { array_unshift($ips, $ip); $ip = false; }
for ($i = 0; $i < count($ips); $i++) {
if (!eregi ("^(10|172.16|192.168).", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_server['remote_addr']);
}
echo get_real_ip();
?>
<?php
if ($http_server_vars["http_x_forwarded_for"])
{
$ip = $http_server_vars["http_x_forwarded_for"];
}
elseif ($http_server_vars["http_client_ip"])
{
$ip = $http_server_vars["http_client_ip"];
}
elseif ($http_server_vars["remote_addr"])
{
$ip = $http_server_vars["remote_addr"];
}
elseif (getenv("http_x_forwarded_for"))
{
$ip = getenv("http_x_forwarded_for");
}
elseif (getenv("http_client_ip"))
{
$ip = getenv("http_client_ip");
}
elseif (getenv("remote_addr"))
{
$ip = getenv("remote_addr");
}
else
{
$ip = "unknown";
}
echo "你的ip:".$ip ;
?>
<?php
if(getenv('http_client_ip')) {
$onlineip = getenv('http_client_ip');
} elseif(getenv('http_x_forwarded_for')) {
$onlineip = getenv('http_x_forwarded_for');
} elseif(getenv('remote_addr')) {
$onlineip = getenv('remote_addr');
} else {
$onlineip = $http_server_vars['remote_addr'];
}
echo $onlineip;
?>
上一篇: 不是啊,他还宣和大人!
下一篇: Snoopy类使用小例子
推荐阅读