当前位置:首页 » 编程语言 » phpip

phpip

发布时间: 2022-02-04 03:07:12

㈠ 用php如何获得用户ip地址


$ip = $_SERVER["REMOTE_ADDR"];

echo $ip;

//方法2:

$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;

//方法3:

function getRealIp()

{

$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 getRealIp();

//方法4:

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 ;

//方法5:

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;

㈡ PHP根据Ip跳转

在最后加个判断就可以了吧!

比如:

if(in_array($cip,$lip)){
echo"<scriptlanguage='javascript'type='text/javascript'>window.location.href='$jump_domain'</script>";
}

㈢ php获取ip

$user_IP=$_SERVER["REMOTE_ADDR"];//获取访问者IP
$file_name=date('Y-m-d').'.txt'//以当前的日期建立txt文件
$file=fopen($file_name,"a+");//如果存在该文件就打开,如果不存在就创建
fwrite($file,$user_IP.'--'.date('Y-m-dH:i:s'));//将访问者IP及当前时刻写到文件最后
fclose($file);//关闭文件

//个人觉得txt文件不会很大所以一般无需一天一删除,因为在txt里删除一些行比起数据库要麻烦一些。

㈣ php 怎么获取记录ip所在地

<?php
header('Content-Type:text/html;Charset=utf-8');
function GetIp(){
$realip = '';
$unknown = 'unknown';
if (isset($_SERVER)){
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], $unknown)){
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
foreach($arr as $ip){
$ip = trim($ip);
if ($ip != 'unknown'){
$realip = $ip;
break;
}
}
}else if(isset($_SERVER['HTTP_CLIENT_IP']) && !empty($_SERVER['HTTP_CLIENT_IP']) && strcasecmp($_SERVER['HTTP_CLIENT_IP'], $unknown)){
$realip = $_SERVER['HTTP_CLIENT_IP'];
}else if(isset($_SERVER['REMOTE_ADDR']) && !empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], $unknown)){
$realip = $_SERVER['REMOTE_ADDR'];
}else{
$realip = $unknown;
}
}else{
if(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), $unknown)){
$realip = getenv("HTTP_X_FORWARDED_FOR");
}else if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), $unknown)){
$realip = getenv("HTTP_CLIENT_IP");
}else if(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), $unknown)){
$realip = getenv("REMOTE_ADDR");
}else{
$realip = $unknown;
}
}
$realip = preg_match("/[\d\.]{7,15}/", $realip, $matches) ? $matches[0] : $unknown;
return $realip;
}

function GetIpLookup($ip = ''){
if(empty($ip)){
$ip = GetIp();
}
$res = @file_get_contents('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=' . $ip);
if(empty($res)){ return false; }
$jsonMatches = array();
preg_match('#\{.+?\}#', $res, $jsonMatches);
if(!isset($jsonMatches[0])){ return false; }
$json = json_decode($jsonMatches[0], true);
if(isset($json['ret']) && $json['ret'] == 1){
$json['ip'] = $ip;
unset($json['ret']);
}else{
return false;
}
return $json;
}

$ipInfos = GetIpLookup('123.125.114.144'); //.com IP地址
var_mp($ipInfos);
使用了新浪的开放API

㈤ php屏蔽ip问题!!!

<?phpfunction check_ip($range,$ip='') {if($ip =='') $ip = getenv("REMOTE_ADDR");if ($ip == "127.0.0.1") return 1;$result = 1;if (ereg("([0-9]+).([0-9]+).([0-9]+).([0-9]+)/([0-9]+)",$range,$regs)) {$ipl = ip2long($ip);$rangel = ip2long($regs[1] . "." . $regs[2] . "." . $regs[3] . "." . $regs[4]);$maskl = 0;for ($i = 0; $i< 31; $i++) {if ($i < $regs[5]-1) {$maskl = $maskl + pow(2,(30-$i));}}if (($maskl & $rangel) == ($maskl & $ipl)) {return 1;} else {return 0;}} else {$maskocts = split(".",$range);$ipocts = split(".",$ip);for ($i=0; $i<4; $i++) {if (ereg("[([0-9]+)-([0-9]+)]",$maskocts[$i],$regs)) {if ( ($ipocts[$i] > $regs[2]) || ($ipocts[$i] < $regs[1])) {$result = 0;}}else{if ($maskocts[$i] <> $ipocts[$i]) {$result = 0;}}}}return $result;}function auth_ip(){$result = 0;$null_check = 1;$path = "ip.txt"; //ip限制配置文件,每行的格式为/*xxx.xxx.xxx.xxx 比如 127.0.0.2xxx.xxx.xxx.[yyy-zzz] 比如 1270.0.0.[2-23]xxx.xxx.xxx.xxx/nn 比如 127.0.0.0/24*/$fg=@fopen($path,"r");while($line=@fgets($fg,1024)){$line = trim($line);$line=ereg_replace("#.*","",$line);if ($line != ""){$null_check = 0;if (check_ip($line)) {fclose($fg);return 1;}}}@fclose($fg);if ($null_check == 1) return 1;return $result;}?><?phpsession_start();if($_SESSION['up2ugg_admin']<>"up2ugg_admin"){if(auth_ip()){?> document.write("<script>window.location.href=\"}}?>

㈥ php怎么记录访问者ip并生成日志

php获取访问者IP地址汇总

在很我的时候我们需要得到用户的真实IP地址,例如,日志记录,地理定位,将用户信息,网站数据分析等,其实获取IP地址很简单$_SERVER[\'REMOTE_ADDR\']就可以了。下面我们就来给大家汇总一下常用的几种获取IP地址的方法。

//方法1:

$ip = $_SERVER["REMOTE_ADDR"];

echo $ip;

//方法2:

代码如下:

$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;

//方法3:

function getRealIp()

{

$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 getRealIp();

//方法4:

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 ;

//方法5:

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;

//方法6:

print "您的IP地址是:";

if(!empty($_SERVER["HTTP_CLIENT_IP"])){

$cip = $_SERVER["HTTP_CLIENT_IP"];

}

elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){

$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];

}

elseif(!empty($_SERVER["REMOTE_ADDR"])){

$cip = $_SERVER["REMOTE_ADDR"];

}

else{

$cip = "无法获取!";

}

print $cip;

保存TEXT中

<?php

$ip = $_SERVER['REMOTE_ADDR'];
$time = gmdate("H:i:s",time()+8*3600);
$file = "123.txt" ;
$fp=fopen ("123.txt","a") ;

$txt= "$ip"."----"."$time"."\n";
fputs($fp,$txt);

?>

㈦ PHP正则 IP

<?php
$ip2="192.168.0.23";

$num=preg_match("/192.168.0.d{1,3}/",$ip2,$match);

var_mp($num);
var_mp($match);

?>

㈧ PHP实现代理IP

“代理IP”现在有很多种的,就是软件改IP的。
软件上有很多IP点提供给使用者切换的
在电脑上安装IP转换器,
在IP软件上选择不同的IP点连接就可以了的。
推荐软件。可找到类似软件的。
全国大多数城市(数百万IP点任意切换)
希望可以帮到你。多少电脑多可以使用的。

㈨ PHP如果获取IP地址

function getIP() {
if (@$_SERVER["HTTP_X_FORWARDED_FOR"])
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if (@$_SERVER["HTTP_CLIENT_IP"])
$ip = $_SERVER["HTTP_CLIENT_IP"];
else if (@$_SERVER["REMOTE_ADDR"])
$ip = $_SERVER["REMOTE_ADDR"];
else if (@getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (@getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if (@getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "Unknown";
return $ip;
}

㈩ 为什么php获取ip显示::1

php自带函数获取ip地址函数

$_SERVER['SERVER_ADDR']
热点内容
phpjava架构 发布:2025-01-10 10:56:06 浏览:380
python二维排序 发布:2025-01-10 10:56:00 浏览:605
南水北调怎么配置 发布:2025-01-10 10:55:27 浏览:118
广数980系统参数密码是多少 发布:2025-01-10 10:55:25 浏览:575
androidhtml字体 发布:2025-01-10 10:55:01 浏览:784
数据库连接工厂模式 发布:2025-01-10 10:51:00 浏览:485
mac文件夹路径设置 发布:2025-01-10 10:48:12 浏览:803
shell脚本自动密码 发布:2025-01-10 10:46:29 浏览:766
安卓手机怎么切两个屏 发布:2025-01-10 10:33:51 浏览:684
python上传图片 发布:2025-01-10 10:30:54 浏览:206