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
-
- Header ('content-Type: text/html; charset = utf-8 ');
- $ Starttime = getmicrotime (); // get the page start execution time
- Define ('wroot', dirname (_ FILE _); // define the program directory
- Function GetIP () {// obtain the IP address
- If ($ _ SERVER ["HTTP_X_FORWARDED_FOR"])
- $ Ip = $ _ SERVER ["HTTP_X_FORWARDED_FOR"];
- Else if ($ _ SERVER ["HTTP_CLIENT_IP"])
- $ Ip = $ _ SERVER ["HTTP_CLIENT_IP"];
- Else if ($ _ SERVER ["REMOTE_ADDR"])
- $ Ip = $ _ SERVER ["REMOTE_ADDR"];
- Else if (getenv ("HTTP_X_FORWARDED_FOR "))
- $ Ip = getenv ("HTTP_X_FORWARDED_FOR ");
- Else if (getenv ("HTTP_CLIENT_IP "))
- $ Ip = getenv ("HTTP_CLIENT_IP ");
- Else if (getenv ("REMOTE_ADDR "))
- $ Ip = getenv ("REMOTE_ADDR ");
- Else
- $ Ip = "Unknown ";
- Return $ ip;
- }
- Define ('_ QQWRY _', WROOT. "/QQWry. Dat"); // ip address library of QQ
- Include_once WROOT. '/QQWry. class. php ';
- $ QQWry = new QQWry;
- $ QQWry-> QQWry (GetIP ());
- $ Country = iconv ('gb2312', 'utf-8', $ QQWry-> Country); // note the encoding. the default address read by QQWry. DAT is GB2312.
- /*
- * Page jump
- */
- If (strstr ($ country, "Zhengzhou ")! = NULL ){
- Echo "zhengzhou.abc.com" // jump to the corresponding city page. In this example, only the URL is printed. the skip code is omitted.
- // Else if... judgment of more cities, code omitted
- Echo $ country. iconv ('gb2312', 'utf-8', $ QQWry-> Local )."
";
- // If the sub-station is not matched, then... Omitted
- }
- /*
- * Get the current page time
- */
- Function getmicrotime (){
- List ($ msec, $ sec) = explode ("", microtime ());
- Return (float) $ sec + (float) $ msec;
- }
- /*
- * Get the page execution time
- */
- Function getruntime ($ starttime ){
- Return getmicrotime ()-$ starttime;
- }
- Printf ('Page Execution time: %. 4f second ', getruntime ($ starttime ));
- ?>