Born under the red flag long in the spring breeze, long soak in the crab society inside so over time there are some of the way of thinking of the crab, just for a while to do one. NET Web site access statistics system, by the way, how to "monitor"
This article mainly introduces the specific implementation of PHP in the city where the IP address is obtained. if you need it, refer to the file directory:
IpLocation----- Qqwry---------- QQWry. Dat----- IpCity. class. php
IpCity. class. php file
PHP determines whether a city can be switched to another city or redirect code based on the IP address. It is quite easy to get the IP address first. The following describes two codes for getting the IP address first. you need to use the QQIP
Get IP AddressCopy codeThe Code is as follows:Function GetIP (){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
The following code judges the user's City Based on the IP address. php judges that the source code of the IP address is completely open.
The following code judges the user's City Based on the IP address. php judges that the source code of the IP
PhpIP retrieval City API (pure IP database)
/**
* Obtain the city name pure IP database based on the IP address
* Edit: bbs.it-home.org
*/
Function convertip ($ ip ){
// IP data file path
File directory:
Iplocation-----Qqwry----------QQWry.Dat-----ipCity.class.php
ipCity.class.php File Code:Copy the Code code as follows:
Class IpCity {
/*** Obtain the corresponding city according to the IP address* @param type $userip User IP
To test, you need to download an IP database, and then save the php code I sent to the php file, and put the javascript code in the html file, to add more cities, you only need to copy elseif in javascript code several times to download an IP
Write a class that traverses directories and replaces file contents in bulk
Write this class before you need it.
Function:
1 traversing all files in the directory (you can specify the suffix name)
2 Bulk Replace file contents (regular, String)
3
File directory:
Iplocation-----Qqwry----------QQWry.Dat-----ipCity.class.php
ipCity.class.php File Code:Copy the Code code as follows:
Class IpCity {
/*** Obtain the corresponding city according to the IP address* @param type $userip User IP
Get IP Address
Copy CodeThe code is as follows:
function GetIP () {
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"
/**
* Get city name based on IP address pure IP database
* edit:bbs.it-home.org
*/
function Convertip ($IP) {
IP Data File path
$dat _path = ' QQWry.Dat ';
Check IP Address
if (!filter_var ($ip,
Discuz 5.0 is not using their own IP data, but the use of pure IP data format, access to the pure IP database a little bit of trouble, its storage format is very special and interesting, specific format analysis refer to the following two links,
Programming function set. The details are as follows:
Read Keyboard Scan codeGet machine dateConverts a floating point number to a string.Clear ScreenDisplay timePrint a rectangleTrim all spaces in the stringSubstringRead characters from a
Discuz 5.0 do not use their own IP data, but the use of pure IP data format, access to the pure IP database a little trouble, its storage format is more special and interesting, the specific format of the analysis of the following two links, other
File directory:
Iplocation-----Qqwry----------QQWry.Dat-----ipCity.class.php
ipCity.class.php File Code:
Copy Code code as follows:
Class IpCity {
/*** According to the IP address to obtain the corresponding city* @param type
1, UTF-8, GB2312 are supported by the Chinese character intercept function
Copy Code code as follows:
/*
Chinese character interception function supported by Utf-8 and gb2312
Cut_str (string, intercept length, start length, coding);
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.