当前位置:网站首页>PHP get real IP
PHP get real IP
2022-07-02 23:24:00 【fuchto】
/**
* Get real IP
* @param int $type
* @param bool $client
* @return mixed
*/
function get_client_ip($type = 0,$client=true)
{
$type = $type ? 1 : 0;
static $ip = NULL;
if ($ip !== NULL) return $ip[$type];
if($client){
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$pos = array_search('unknown',$arr);
if(false !== $pos) unset($arr[$pos]);
$ip = trim($arr[0]);
}elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}elseif (isset($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
}
}elseif (isset($_SERVER['REMOTE_ADDR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
}
// prevent IP forge
$long = sprintf("%u",ip2long($ip));
$ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
return $ip[$type];
}边栏推荐
- 为什么RTOS系统要使用MPU?
- Sword finger offer II 099 Sum of minimum paths - double hundred code
- [adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)
- CDN 加速,需要域名先备案
- Loss function~
- 密码技术---密钥和SSL/TLS
- Makefile configuration of Hisilicon calling interface
- [favorite poems] OK, song
- Which common ports should the server open
- Win11自动关机设置在哪?Win11设置自动关机的两种方法
猜你喜欢
随机推荐
Configuration clic droit pour choisir d'ouvrir le fichier avec vs Code
内网渗透 | 手把手教你如何进行内网渗透
20220524_数据库过程_语句留档
密码技术---分组密码的模式
Is 408 not fragrant? The number of universities taking the 408 examination this year has basically not increased!
Tronapi wave field interface - source code without encryption - can be opened twice - interface document attached - packaging based on thinkphp5 - detailed guidance of the author - July 1, 2022 08:43:
【STL源码剖析】仿函数(待补充)
Deep analysis of data storage in memory - C language
CDN 加速,需要域名先备案
Call vs2015 with MATLAB to compile vs Project
Potplayer set minimized shortcut keys
vim区间删行注释
Three solutions to frequent sticking and no response of explorer in win11 system
設置單擊右鍵可以選擇用VS Code打開文件
基于Pyqt5工具栏按钮可实现界面切换-1
Temperature measurement and display of 51 single chip microcomputer [simulation]
深度剖析数据在内存中的存储----C语言篇
Compose 中的 'ViewPager' 详解 | 开发者说·DTalk
Getting started with golang: for Range an alternative method of modifying the values of elements in slices
golang入门:for...range修改切片中元素的值的另类方法









