PHP gets user IP address

PHP中文网
Release: 2016-08-08 09:18:57
Original
1124 people have browsed it

PHP obtains user IP address

<?php

function getClientIp() {
	$uip = &#39;&#39;;
	if(!empty($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;]) && strcasecmp($_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;], &#39;unknow&#39;)) {
		$uip = $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;];
		strpos($uip, &#39;,&#39;) && list($uip) = explode(&#39;,&#39;, $uip);
	} elseif(!empty($_SERVER[&#39;HTTP_CLIENT_IP&#39;]) && strcasecmp($_SERVER[&#39;HTTP_CLIENT_IP&#39;], &#39;unknow&#39;)) {
		$uip = $_SERVER[&#39;HTTP_CLIENT_IP&#39;];
	} elseif(!empty($_SERVER[&#39;REMOTE_ADDR&#39;]) && strcasecmp($_SERVER[&#39;REMOTE_ADDR&#39;], &#39;unknow&#39;)) {
		$uip = $_SERVER[&#39;REMOTE_ADDR&#39;];
	}
	return $uip;
}
echo getClientIp();
Copy after login

The above introduces PHP to obtain user IP address, including aspects. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!