当前位置:网站首页>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];
}
边栏推荐
- 移动端 1px 像素兼容性问题,实现1px 边框
- Win11启用粘滞键关闭不了怎么办?粘滞键取消了但不管用怎么解决
- Jerry's prototype will trigger shutdown after multiple touches [chapter]
- Successfully changed Splunk default URL root path
- 海思调用接口之Makefile配置
- Alibaba cloud award winning experience: how to use polardb-x
- Loss function~
- 地平线2022年4月最新方案介绍
- BBR 遭遇 CUBIC
- 20220524_数据库过程_语句留档
猜你喜欢
[redis notes] compressed list (ziplist)
golang入门:for...range修改切片中元素的值的另类方法
基于Pyqt5工具栏按钮可实现界面切换-2
[Solved] Splunk: Cannot get username when all users are selected“
STM32之ADC
Generics and reflection, this is enough
Getting started with golang: for Range an alternative method of modifying the values of elements in slices
购买完域名之后能干什么事儿?
为什么RTOS系统要使用MPU?
数字图像处理实验目录
随机推荐
Construction of Hisilicon 3559 universal platform: rotation operation on the captured YUV image
密码技术---分组密码的模式
基于Pyqt5工具栏按钮可实现界面切换-2
Use the scroll bar of souI when using the real window in souI
内网渗透 | 手把手教你如何进行内网渗透
Jerry's built-in short press and long press, no matter how long it is, it is a short press [chapter]
ADC of stm32
Jerry's fast touch does not respond [chapter]
Use of recyclerview with viewbinding
Methods to solve the tampering of Chrome browser and edeg browser homepage
解决:exceptiole ‘xxxxx.QRTZ_LOCKS‘ doesn‘t exist以及mysql的my.cnf文件追加lower_case_table_names后启动报错
Getting started with golang: for Range an alternative method of modifying the values of elements in slices
Motivation du Protocole de chiffrement avancé AES
Minimum spanning tree
Learning Websites commonly used by circuit designers
Which common ports should the server open
聊聊内存模型与内存序
golang中new与make的区别
Cryptographic technology -- key and ssl/tls
RecyclerView结合ViewBinding的使用