In this paper, we describe the encapsulation class of PHP for client and server IP. Share to everyone for your reference, as follows:
Client IP-related variables:
1. $_server[' REMOTE_ADDR '; Client IP, which may be the IP of the user or the IP of the proxy.
2. $_server[' http_client_ip '; Proxy-side IP, may exist, can be forged.
3. $_server[' http_x_forwarded_for '; The user is the agent in which IP is used, which may exist and can be forged.
Server-side IP-related variables:
1. $_server["SERVER_NAME"), need to use function gethostbyname () to obtain. This variable can be displayed correctly both on the server side and on the client.
2. $_server["Server_addr"], on the server side test: 127.0.0.1 (this is related to the Bindaddress setting value in httpd.conf). The test results on the client are correct.
Classes are as follows:
Class getip{function ClientIP () {$cIP = getenv (' remote_addr '), $cIP 1 = getenv (' http_x_forwarded_for '); $cIP 2 = getenv (' HT Tp_client_ip '); $cIP 1? $cIP = $cIP 1:null; $cIP 2? $cIP = $cIP 2:null; return $cIP; } function ServerIP () {return gethostbyname ($_server["SERVER_NAME"]);}} $getIP = new GetIP (); $clientIp = Getip::clientip (); $serverIp = Getip::serverip (); Echo ' Client IP is ', $clientIp, '
'; Echo ' Server IP is ', $serverIp, '
';
More readers interested in PHP related content can view the topic: "PHP Network Programming Skills Summary", "Php Curl Usage Summary", "PHP Socket Usage Summary", "PHP Regular Expression Usage summary", "PHP string (String) Usage Summary", " PHP Arrays (array) operation tips, "PHP Math Skills Summary", "PHP Object-oriented Programming tutorial", "PHP Data structure and algorithm tutorial", "PHP Programming algorithm Summary" and "PHP common database Operation Skills Summary"
I hope this article is helpful to you in PHP programming.
The above describes the netcom client download IP php to obtain the client and server-side IP encapsulation class, including the netcom client download IP content, I hope that the PHP tutorial interested in a friend helpful.