當前位置:首頁 » 編程語言 » 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']
熱點內容
安卓hostapd源在哪裡 發布:2025-01-10 02:31:53 瀏覽:568
二級c語言證書查詢 發布:2025-01-10 02:20:25 瀏覽:457
大眾車的鍵盤鎖密碼是多少 發布:2025-01-10 02:20:24 瀏覽:240
如何將資料庫加密碼 發布:2025-01-10 02:14:46 瀏覽:952
阿里雲怎麼買游戲伺服器 發布:2025-01-10 02:01:51 瀏覽:847
dota和英雄聯盟哪個吃配置 發布:2025-01-10 02:00:33 瀏覽:181
華為雲伺服器怎麼登錄 發布:2025-01-10 01:59:48 瀏覽:127
東南大學知網伺服器地址 發布:2025-01-10 01:54:40 瀏覽:933
安卓手機剪映怎麼修改成4k幀率 發布:2025-01-10 01:08:21 瀏覽:951
微信哪個版本不要求配置 發布:2025-01-10 01:07:31 瀏覽:405