国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial php怎么獲取真實(shí)IP

php怎么獲取真實(shí)IP

Jun 13, 2016 am 11:15 AM
http nbsp remote server

php如何獲取真實(shí)IP
試了網(wǎng)上很多代碼都不行,但是ip138每次都能顯示我的真實(shí)ip。特求各位大俠支招。

比如我用一般的php獲得的我的ip地址是:60.55.8.229?-?浙江寧波

但是ip38.com獲取的我的IP地址是:[42.196.192.67]?來自:上海市?長(zhǎng)城寬帶

ip138才是正確的。

我在醫(yī)院里測(cè)試也是這樣,自己的php代碼獲取的IP是浙江杭州

但是ip138卻能獲得我的真實(shí)ip,上海交通大學(xué)

我現(xiàn)在用的PHP代碼如下:

function GetIP(){ <br />if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) <br />$ip = getenv("HTTP_CLIENT_IP"); <br />else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) <br />$ip = getenv("HTTP_X_FORWARDED_FOR"); <br />else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) <br />$ip = getenv("REMOTE_ADDR"); <br />else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) <br />$ip = $_SERVER['REMOTE_ADDR']; <br />else <br />$ip = "unknown"; <br />return($ip); <br />} <br />echo GetIP();


------解決方案--------------------
這是我的方法:
Function curIp(){<br />		$ip='';<br />		IF(Getenv('HTTP_CLIENT_IP') And StrCaseCmp(Getenv('HTTP_CLIENT_IP'),'unknown')){<br />			$ip=Getenv('HTTP_CLIENT_IP');<br />		}ElseIF(Getenv('HTTP_X_FORWARDED_FOR') And StrCaseCmp(Getenv('HTTP_X_FORWARDED_FOR'),'unknown')){<br />			$ip=Getenv('HTTP_X_FORWARDED_FOR');<br />		}ElseIF(Getenv('REMOTE_ADDR')And StrCaseCmp(Getenv('REMOTE_ADDR'),'unknown')){<br />			$ip=Getenv('REMOTE_ADDR');<br />		}ElseIF(isset($_SERVER['REMOTE_ADDR']) And $_SERVER['REMOTE_ADDR'] And StrCaseCmp($_SERVER['REMOTE_ADDR'],'unknown')){<br />			$ip=$_SERVER['REMOTE_ADDR'];<br />		}Else{<br />			$ip='127.0.0.1';<br />		}<br />		Return $ip;<br />	}

------解決方案--------------------
function?real_ip()
{
static?$realip?=?NULL;

if?($realip?!==?NULL)
{
return?$realip;
}

if?(isset($_SERVER))
{
if?(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$arr?=?explode(',',?$_SERVER['HTTP_X_FORWARDED_FOR']);

/*?取X-Forwarded-For中第一個(gè)非unknown的有效IP字符串?*/
foreach?($arr?AS?$ip)
{
$ip?=?trim($ip);

if?($ip?!=?'unknown')
{
$realip?=?$ip;

break;
}
}
}
elseif?(isset($_SERVER['HTTP_CLIENT_IP']))
{
$realip?=?$_SERVER['HTTP_CLIENT_IP'];
}
else
{
if?(isset($_SERVER['REMOTE_ADDR']))
{
$realip?=?$_SERVER['REMOTE_ADDR'];
}
else
{
$realip?=?'0.0.0.0';
}
}
}
else
{
if?(getenv('HTTP_X_FORWARDED_FOR'))
{
$realip?=?getenv('HTTP_X_FORWARDED_FOR');
}
elseif?(getenv('HTTP_CLIENT_IP'))
{
$realip?=?getenv('HTTP_CLIENT_IP');
}
else
{
$realip?=?getenv('REMOTE_ADDR');
}
}
$onlineip?=?null;
preg_match("/[\d\.]{7,15}/",?$realip,?$onlineip);
$realip?=?!empty($onlineip[0])???$onlineip[0]?:?'0.0.0.0';

return?$realip;
}
------解決方案--------------------

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

What does http status code 520 mean? What does http status code 520 mean? Oct 13, 2023 pm 03:11 PM

HTTP status code 520 means that the server encountered an unknown error while processing the request and cannot provide more specific information. Used to indicate that an unknown error occurred when the server was processing the request, which may be caused by server configuration problems, network problems, or other unknown reasons. This is usually caused by server configuration issues, network issues, server overload, or coding errors. If you encounter a status code 520 error, it is best to contact the website administrator or technical support team for more information and assistance.

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

How to install, uninstall, and reset Windows server backup How to install, uninstall, and reset Windows server backup Mar 06, 2024 am 10:37 AM

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS Sep 26, 2023 am 11:19 AM

How to use NginxProxyManager to implement automatic jump from HTTP to HTTPS. With the development of the Internet, more and more websites are beginning to use the HTTPS protocol to encrypt data transmission to improve data security and user privacy protection. Since the HTTPS protocol requires the support of an SSL certificate, certain technical support is required when deploying the HTTPS protocol. Nginx is a powerful and commonly used HTTP server and reverse proxy server, and NginxProxy

What is http status code 403? What is http status code 403? Oct 07, 2023 pm 02:04 PM

HTTP status code 403 means that the server rejected the client's request. The solution to http status code 403 is: 1. Check the authentication credentials. If the server requires authentication, ensure that the correct credentials are provided; 2. Check the IP address restrictions. If the server has restricted the IP address, ensure that the client's IP address is restricted. Whitelisted or not blacklisted; 3. Check the file permission settings. If the 403 status code is related to the permission settings of the file or directory, ensure that the client has sufficient permissions to access these files or directories, etc.

See all articles