当前位置:网站首页>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];
}边栏推荐
- RuntimeError: no valid convolution algorithms available in CuDNN
- Yolox enhanced feature extraction network panet analysis
- 海思调用接口之Makefile配置
- Print out mode of go
- Getting started with golang: for Range an alternative method of modifying the values of elements in slices
- “一个优秀程序员可抵五个普通程序员!”
- 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:
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验3 按键输入实验(学习笔记)
- Talk about memory model and memory order
- 为什么RTOS系统要使用MPU?
猜你喜欢

MySQL queries nearby data And sort by distance
![[hardware] origin of standard resistance value](/img/d1/b9184c508d363eb0fa018ea6a57a10.png)
[hardware] origin of standard resistance value

Methods to solve the tampering of Chrome browser and edeg browser homepage

LINQ usage collection in C #

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

第三方支付功能测试点【杭州多测师_王sir】【杭州多测师】

Go basic constant definition and use

BBR 遭遇 CUBIC
![[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)](/img/a3/d8421ea1539eba08bf7a5a629d92e6.jpg)
[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)

ServletContext learning diary 1
随机推荐
实现BottomNavigationView和Navigation联动
Static file display problem
Ping domain name error unknown host, NSLOOKUP / system d-resolve can be resolved normally, how to Ping the public network address?
Typical case of data annotation: how does jinglianwen technology help enterprises build data solutions
深度剖析数据在内存中的存储----C语言篇
QT qpprogressbar details
Win11如何开启目视控制?Win11开启目视控制的方法
Arduino - character judgment function
Three solutions to frequent sticking and no response of explorer in win11 system
Mask R-CNN
Quantitative analysis of PSNR, SSIM and RMSE
Solving ordinary differential equations with MATLAB
Editor Caton
[adjustment] postgraduate enrollment of Northeast Petroleum University in 2022 (including adjustment)
Pandora IOT development board learning (HAL Library) - Experiment 3 key input experiment (learning notes)
Numerical solution of partial differential equations with MATLAB
潘多拉 IOT 开发板学习(HAL 库)—— 实验4 串口通讯实验(学习笔记)
vim区间删行注释
非路由组件之头部组件和底部组件书写
Is 408 not fragrant? The number of universities taking the 408 examination this year has basically not increased!