当前位置:网站首页>PHP obtains the IP address, and the apache2 server runs without error
PHP obtains the IP address, and the apache2 server runs without error
2022-06-25 09:35:00 【silno】
this ip The advantage of getting a function is apahce2 No error is reported at runtime .
function getRealIp()
{
$ip=false;
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
for ($i = 0; $i < count($ips); $i++) {
if (!eregi ("^(10│172.16│192.168).", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
echo getRealIp();
The following code page can get ip Address , but apache2 Operation error reporting
PHP Notice: Use of undefined constant HTTP_X_FORWARDED_FOR - assumed 'HTTP_X_FORWARDED_FOR'
function getip()
{
if (isset($_SERVER))
{
if (isset($_SERVER[HTTP_X_FORWARDED_FOR]) && strcasecmp($_SERVER[HTTP_X_FORWARDED_FOR], "unknown"))// agent
{
$realip = $_SERVER[HTTP_X_FORWARDED_FOR];
}
elseif(isset($_SERVER[HTTP_CLIENT_IP]) && strcasecmp($_SERVER[HTTP_CLIENT_IP], "unknown"))
{
$realip = $_SERVER[HTTP_CLIENT_IP];
}
elseif(isset($_SERVER[REMOTE_ADDR]) && strcasecmp($_SERVER[REMOTE_ADDR], "unknown"))
{
$realip = $_SERVER[REMOTE_ADDR];
}
else
{
$realip = 'unknown';
}
}
else
{
if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
{
$realip = getenv("HTTP_X_FORWARDED_FOR");
}
elseif(getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
{
$realip = getenv("HTTP_CLIENT_IP");
}
elseif(getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
{
$realip = getenv("REMOTE_ADDR");
}
else
{
$realip = 'unknown';
}
}
return $realip;
}
边栏推荐
- Remove the mosaic, there's a way, attached with the running tutorial
- Where is safe for FTSE A50 to open an account
- [zero foundation understanding innovation and entrepreneurship competition] overall cognition and introduction of mass entrepreneurship and innovation competition (including FAQs and integration of bl
- Compare and explain common i/o models
- C语言刷题随记 —— 猴子吃桃
- Jmeter中的断言使用讲解
- [buuctf.reverse] 121-125
- Socket programming -- epoll model
- 《乔布斯传》英文原著重点词汇笔记(六)【 chapter three 】
- 使用Navicat对比多环境数据库数据差异和结构差异,以及自动DML和DDL脚本
猜你喜欢
备战2022年金九银十必问的1000道Android面试题及答案整理,彻底解决面试的烦恼
JMeter interface test, associated interface implementation steps (token)
Numpy numpy中的meshgrid()函数
浅谈Mysql底层索引原理
The first techo day Tencent technology open day, 628 waiting for you!
Analysis on the bottom calling process of micro service calling component ribbon
Oracle one line function Encyclopedia
Where are the hotel enterprises that have been under pressure since the industry has warmed up in spring?
Nodejs using the express framework demo
2022 postgraduate entrance examination experience post -- Alibaba Business School of Hangzhou Normal University -- management science and Engineering (including the recommendation of books and course
随机推荐
从海量手机号中匹配某一个手机号
十大券商开户风险大吗,安全靠谱吗?
PMP考试多少分算通过?
Applet cloud development joint table data query and application in cloud function
Matplotlib decision boundary drawing function plot in Matplotlib_ decision_ Boundary and plt Detailed explanation of contour function
x86的编码格式
Mapping mode of cache
《乔布斯传》英文原著重点词汇笔记(六)【 chapter three 】
行业春寒回暖,持续承压的酒店企业于何处破局?
Creating a binary tree (binary linked list) from a generalized table
Is it harder to find a job in 2020? Do a good job in these four aspects and find a good job with high salary
[learn C from me and master the key to programming] insertion sort of eight sorts
[zufe school competition] difficulty classification and competition suggestions of common competitions in the school (taking Zhejiang University of Finance and economics as an example)
Flitter gets the height of the top status bar
5、 Project practice --- identifying man and horse
Oracle-单行函数大全
Atguigu---01-scaffold
[competition -kab micro entrepreneurship competition] KAB National College Students' micro entrepreneurship action participation experience sharing (including the idea of writing the application form)
Jmeter接口测试,关联接口实现步骤(token)
请问在手机上开户股票,还是去证券公司开户安全?