PHP determines the IP client

Source: Internet
Author: User
As for how to obtain the client IP address, you don't need to talk about it in detail. but to take care of the same Cainiao as me, I 'd like to paste the code for displaying the page by the way.

As for how to obtain the client IP address, you don't need to talk about it in detail. but to take care of the same Cainiao as me, I 'd like to paste the code for displaying the page by the way:
PHP code

 

PHP code
  1. Header ('content-Type: text/html; charset = utf-8 ');
  2. $ Starttime = getmicrotime (); // get the page start execution time
  3. Define ('wroot', dirname (_ FILE _); // define the program directory
  4. Function GetIP () {// obtain the IP address
  5. If ($ _ SERVER ["HTTP_X_FORWARDED_FOR"])
  6. $ Ip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"];
  7. Else if ($ _ SERVER ["HTTP_CLIENT_IP"])
  8. $ Ip = $ _ SERVER ["HTTP_CLIENT_IP"];
  9. Else if ($ _ SERVER ["REMOTE_ADDR"])
  10. $ Ip = $ _ SERVER ["REMOTE_ADDR"];
  11. Else if (getenv ("HTTP_X_FORWARDED_FOR "))
  12. $ Ip = getenv ("HTTP_X_FORWARDED_FOR ");
  13. Else if (getenv ("HTTP_CLIENT_IP "))
  14. $ Ip = getenv ("HTTP_CLIENT_IP ");
  15. Else if (getenv ("REMOTE_ADDR "))
  16. $ Ip = getenv ("REMOTE_ADDR ");
  17. Else
  18. $ Ip = "Unknown ";
  19. Return $ ip;
  20. }
  21. Define ('_ QQWRY _', WROOT. "/QQWry. Dat"); // ip address library of QQ
  22. Include_once WROOT. '/QQWry. class. php ';
  23. $ QQWry = new QQWry;
  24. $ QQWry-> QQWry (GetIP ());
  25. $ Country = iconv ('gb2312', 'utf-8', $ QQWry-> Country); // note the encoding. the default address read by QQWry. DAT is GB2312.
  26. /*
  27. * Page jump
  28. */
  29. If (strstr ($ country, "Zhengzhou ")! = NULL ){
  30. Echo "zhengzhou.abc.com" // jump to the corresponding city page. In this example, only the URL is printed. the skip code is omitted.
  31. // Else if... judgment of more cities, code omitted
  32. Echo $ country. iconv ('gb2312', 'utf-8', $ QQWry-> Local )."
    ";
  33. // If the sub-station is not matched, then... Omitted
  34. }
  35. /*
  36. * Get the current page time
  37. */
  38. Function getmicrotime (){
  39. List ($ msec, $ sec) = explode ("", microtime ());
  40. Return (float) $ sec + (float) $ msec;
  41. }
  42. /*
  43. * Get the page execution time
  44. */
  45. Function getruntime ($ starttime ){
  46. Return getmicrotime ()-$ starttime;
  47. }
  48. Printf ('Page Execution time: %. 4f second ', getruntime ($ starttime ));
  49. ?>

 


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.