当前位置:网站首页>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];
}边栏推荐
- 阿里云有奖体验:如何使用 PolarDB-X
- psnr,ssim,rmse三个指标的定量分析
- The use of 8255 interface chip and ADC0809
- SharedPreferences 保存List<Bean> 到本地并解决com.google.gson.internal.LinkedTreeMap cannot be cast to异常
- China Academy of information technology, Tsinghua University, Tencent security, cloud native security, industry university research and use strong alliance!
- Eight bit responder [51 single chip microcomputer]
- 密码技术---分组密码的模式
- 门牌制作 C语言
- Easyclick, EC Quanlang network verification source code
- Connexion à distance de la tarte aux framboises en mode visionneur VNC
猜你喜欢

YOLOX加强特征提取网络Panet分析

Three solutions to frequent sticking and no response of explorer in win11 system

海思 VI接入视频流程

Go language sqlx library operation SQLite3 database addition, deletion, modification and query

从底层结构开始学习FPGA----Xilinx ROM IP的定制与测试
![[npuctf2020]ezlogin XPath injection](/img/6e/dac4dfa0970829775084bada740542.png)
[npuctf2020]ezlogin XPath injection

Explain promise usage in detail

Solution: exceptiole 'xxxxx QRTZ_ Locks' doesn't exist and MySQL's my CNF file append lower_ case_ table_ Error message after names startup

Hisilicon VI access video process

Go basic data type
随机推荐
BBR encounters cubic
Go basic data type
密码技术---分组密码的模式
The use of 8255 interface chip and ADC0809
Construction of Hisilicon 3559 universal platform: draw a frame on the captured YUV image
RecyclerView结合ViewBinding的使用
Prometheus deployment
設置單擊右鍵可以選擇用VS Code打開文件
Redis 过期策略+conf 记录
深度剖析数据在内存中的存储----C语言篇
Print out mode of go
"A good programmer is worth five ordinary programmers!"
How does win11 turn on visual control? Win11 method of turning on visual control
【直播预约】数据库OBCP认证全面升级公开课
Quantitative analysis of PSNR, SSIM and RMSE
提交代码流程
内网渗透 | 手把手教你如何进行内网渗透
Golang common settings - modify background
【Proteus仿真】51单片机+LCD12864推箱子游戏
【Redis笔记】压缩列表(ziplist)