Get the visitor's real IP address in php_PHP tutorial

WBOY
Release: 2016-07-13 16:54:36
Original
1129 people have browsed it

php gets the visitor’s real IP address Sometimes we need to get the user's real IP address, for example, logging, geolocation, user information, website data analysis, etc. In fact, getting the IP address is very simple, just $_SERVER['REMOTE_ADDR'].

php tutorial to get the visitor’s real ip address
Sometimes we need to get the user's real IP address, for example, logging, geolocation, user information, website data analysis, etc. In fact, getting the IP address is very simple, just $_server['remote_addr'].
*/
//The simplest method

$ip = $_server['remote_addr'];

//As long as you use a proxy in the above method, you cannot get the real IP address. There are more detailed methods below

echo "remote addr: " . $_server['remote_addr']."
";
echo "x forward: " . $_server['http_x_forwarded_for']."
";
echo "clien ip: " . $_server['http_client_ip']."
";

//Okay, let’s look at an example.

function getip() {
$ip = $_server['remote_addr'];
if (!empty($_server['http_client_ip'])) { 
$ip = $_server['http_client_ip'];
} elseif (!empty($_server['http_x_forwarded_for'])) {              
$ip = $_server['http_x_forwarded_for'];

Return $ip;
}

/*
If it is an encrypted proxy, the real IP address cannot be obtained.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631731.htmlTechArticlephp gets the visitor’s real IP address. Sometimes we need to get the user’s real IP address, for example, logs Recording, geolocation, user information, website data analysis, etc., actually obtain...
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!