当前位置:网站首页>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];
}边栏推荐
- Temperature measurement and display of 51 single chip microcomputer [simulation]
- Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
- Introduction to the latest plan of horizon in April 2022
- 阿里云有奖体验:如何使用 PolarDB-X
- Win11启用粘滞键关闭不了怎么办?粘滞键取消了但不管用怎么解决
- QT qpprogressbar details
- Jinglianwen technology's low price strategy helps AI enterprises reduce model training costs
- Lambda expression: an article takes you through
- 详解Promise使用
- Golang common settings - modify background
猜你喜欢

Why does RTOS system use MPU?

Catalogue of digital image processing experiments

Set right click to select vs code to open the file

Mask R-CNN

Lambda expression: an article takes you through
![[redis notes] compressed list (ziplist)](/img/83/ff38fabb1baebc5fa4d3d72da315dc.png)
[redis notes] compressed list (ziplist)

内网渗透 | 手把手教你如何进行内网渗透

4 special cases! Schools in area a adopt the re examination score line in area B!

解决:exceptiole ‘xxxxx.QRTZ_LOCKS‘ doesn‘t exist以及mysql的my.cnf文件追加lower_case_table_names后启动报错

详解Promise使用
随机推荐
密码技术---密钥和SSL/TLS
从底层结构开始学习FPGA----Xilinx ROM IP的定制与测试
Potplayer set minimized shortcut keys
psnr,ssim,rmse三个指标的定量分析
The first batch of Tencent cloud completed the first cloud native security maturity assessment in China
Which common ports should the server open
STM32之ADC
Looking at Ctrip's toughness and vision from the Q1 financial report in 2022
Ping domain name error unknown host, NSLOOKUP / system d-resolve can be resolved normally, how to Ping the public network address?
[Yangcheng cup 2020] easyphp
景联文科技低价策略帮助AI企业降低模型训练成本
Jerry's fast touch does not respond [chapter]
20220527_ Database process_ Statement retention
面试过了,起薪16k
Chow-Liu Tree
Golang common settings - modify background
1px pixel compatibility of mobile terminal, 1px border
Pandora IOT development board learning (HAL Library) - Experiment 3 key input experiment (learning notes)
The difference between new and make in golang
数据标注典型案例,景联文科技如何助力企业搭建数据方案