PHP gets client and server-side IP

Source: Internet
Author: User

IP variables for the client:

$_server[' REMOTE_ADDR ': Client IP, may also be proxy IP

$_server[' http_client_ip ': Proxy-side IP, may exist, may also be forged

$_server[' http_x_forward_for ': The ID that the user uses on which IP, may exist, or may be forged

IP variables on the server side:

$_server[' server_name ': You need to use the function gethostname () to get it, whether it is the server side or the client can display normally.

$_server[' server_addr ': Server-side IP address, test IP address on server side, test normal on client

Getnev get the environment variables for the system:

Example:

<?phpclass GetIP () {     function ClientIP () {    $cIP = getenv ($_server[' remote_addr ']);    $cIP 1 = getenv ($_server[' http_x_forword_for ');    $cIP 2 = getenv ($_server[' http_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 ();       ? >

  

PHP gets client and server-side IP

Related Article

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.