Home > Backend Development > PHP Tutorial > 005-PHP gets the visitor's real IP

005-PHP gets the visitor's real IP

不言
Release: 2023-03-23 10:14:01
Original
1580 people have browsed it

The content of this article is about PHP getting the real IP of the visitor. Now I share it with everyone. Friends in need can take a look


/**
* 获取来访者的真实IP
*
*/

function getRealIp() {
	static $realip = null;
	if($realip !== null) {
		return $realip;
	}

	if(getenv('REMOTE_ADDR')) {
		$realip = getenv('REMOTE_ADDR');
	} else if(getenv('HTTP_CLIENT_IP')) {
		$realip = getenv('HTTP_CLIENT_IP');
	} else if (getenv('HTTP_X_FROWARD_FOR')) {
		$realip = getenv('HTTP_X_FROWARD_FOR');
	}

	return $realip;	
}
Copy after login



Related recommendations:

004-PHP image upload example

003 - CI in your Using CodeIgniter resources in the class library

The above is the detailed content of 005-PHP gets the visitor's real IP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template