当前位置:网站首页>php 获取真实ip
php 获取真实ip
2022-07-02 22:13:00 【fuchto】
/**
* 获取真实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'];
}
// 防止IP伪造
$long = sprintf("%u",ip2long($ip));
$ip = $long ? array($ip, $long) : array('0.0.0.0', 0);
return $ip[$type];
}边栏推荐
- Hisilicon VI access video process
- [redis notes] compressed list (ziplist)
- 在SOUI里使用真窗口时使用SOUI的滚动条
- Solving ordinary differential equations with MATLAB
- Construction of Hisilicon 3559 universal platform: draw a frame on the captured YUV image
- Jerry's fast touch does not respond [chapter]
- [Yangcheng cup 2020] easyphp
- 分布式监控系统zabbix
- [hardware] origin of standard resistance value
- [npuctf2020]ezlogin XPath injection
猜你喜欢
![[chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM](/img/5d/c23ec16df6ce8d78207b635f59dc20.png)
[chestnut sugar GIS] how does global mapper batch produce ground contour lines through DSM

BBR 遭遇 CUBIC

AES高級加密協議的動機闡述

严守工期,确保质量,这家AI数据标注公司做到了!

Deep analysis of data storage in memory - C language

設置單擊右鍵可以選擇用VS Code打開文件
![[favorite poems] OK, song](/img/1a/e4a4dcca494e4c7bb0e3568f708288.png)
[favorite poems] OK, song

RecyclerView结合ViewBinding的使用
![[hardware] origin of standard resistance value](/img/d1/b9184c508d363eb0fa018ea6a57a10.png)
[hardware] origin of standard resistance value

Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
随机推荐
[redis notes] compressed list (ziplist)
Successfully changed Splunk default URL root path
深度剖析数据在内存中的存储----C语言篇
Splunk audit setting
密码技术---密钥和SSL/TLS
[npuctf2020]ezlogin XPath injection
Go project operation method
Mask R-CNN
Set right click to select vs code to open the file
海思调用接口之Makefile配置
Jerry's fast touch does not respond [chapter]
Realize the linkage between bottomnavigationview and navigation
Is 408 not fragrant? The number of universities taking the 408 examination this year has basically not increased!
Getting started with golang: for Range an alternative method of modifying the values of elements in slices
Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
容器化技术在嵌入式领域的应用
Introduction to the latest plan of horizon in April 2022
Lc173. Binary search tree iterator
编辑卡顿
The difference between new and make in golang