Netcom client Download IP PHP get client and server-side IP encapsulation class

Source: Internet
Author: User
Tags php programming php regular expression
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.