Home  >  Article  >  Backend Development  >  005-PHP gets the visitor’s real IP

005-PHP gets the visitor’s real IP

不言
不言Original
2018-04-08 14:46:151494browse

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;	
}



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!

Statement:
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