当前位置:网站首页>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];
}
边栏推荐
- 20220524_数据库过程_语句留档
- 为什么RTOS系统要使用MPU?
- Looking at Ctrip's toughness and vision from the Q1 financial report in 2022
- @BindsInstance在Dagger2中怎么使用
- 公司里只有一个测试是什么体验?听听他们怎么说吧
- Methods to solve the tampering of Chrome browser and edeg browser homepage
- 2016. maximum difference between incremental elements
- Is 408 not fragrant? The number of universities taking the 408 examination this year has basically not increased!
- Go basic constant definition and use
- Solution: exceptiole 'xxxxx QRTZ_ Locks' doesn't exist and MySQL's my CNF file append lower_ case_ table_ Error message after names startup
猜你喜欢
密码技术---分组密码的模式
Mask R-CNN
力扣刷题(2022-6-28)
CDN acceleration requires the domain name to be filed first
Brief introduction of emotional dialogue recognition and generation
RuntimeError: no valid convolution algorithms available in CuDNN
Golang common settings - modify background
潘多拉 IOT 开发板学习(HAL 库)—— 实验4 串口通讯实验(学习笔记)
详解Promise使用
(stinger) use pystinger Socks4 to go online and not go out of the network host
随机推荐
Pandora IOT development board learning (HAL Library) - Experiment 4 serial port communication experiment (learning notes)
第三方支付功能测试点【杭州多测师_王sir】【杭州多测师】
Application of containerization technology in embedded field
聊聊内存模型与内存序
PotPlayer设置最小化的快捷键
Deep analysis of data storage in memory - C language
Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
“一个优秀程序员可抵五个普通程序员!”
Editor Caton
基于Pyqt5工具栏按钮可实现界面切换-2
Troubleshooting the cause of the crash when STM32 serial port dam receives 253 bytes
Golang common settings - modify background
Go project operation method
"A good programmer is worth five ordinary programmers!"
Remote connection of raspberry pie by VNC viewer
Yolox enhanced feature extraction network panet analysis
Compose 中的 'ViewPager' 详解 | 开发者说·DTalk
[Yangcheng cup 2020] easyphp
BBR 遭遇 CUBIC
Easyclick, EC Quanlang network verification source code