PHP implementation According to the IP address of the city of the method, IP located in the provinces and cities
Ways to get their geographic location (provinces, cities, etc.) based on existing IP addresses
function Getiplookup ($ip = ") { if (empty ($ip)) { return ' Please enter the IP address '; } $res = @file_get_contents (' http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip= '. $ip); if (empty ($res)) {return false;} $jsonMatches = Array (); Preg_match (' #\{.+?\}# ', $res, $jsonMatches); if (!isset ($jsonMatches [0])) {return false;} $json = Json_decode ($jsonMatches [0], true); if (Isset ($json [' ret ']) && $json [' ret '] = = 1) { $json [' ip '] = $IP; unset ($json [' ret ']); } else{ return false; } return $json; } $ipInfos = Getiplookup (' 123.125.114.144 '); Baidu.com IP Address
and send a simplified version of
function getipaddress () { $ipContent = file_get_contents ("http://int.dpool.sina.com.cn/iplookup/ Iplookup.php?format=js "); $jsonData = explode ("=", $ipContent); $jsonAddress = substr ($jsonData [1], 0,-1); return $jsonAddress; } $ip _info=json_decode (Getipaddress ());
PHP enables city switching or jumping based on IP address
Here, in fact, the problem is very simple, with simple JS on all. Paragraph c is as follows:
Jump to specified page according to IP address JS get the city
var city= ' <?echo ipCity ($xp _userip);? > '; Jump to a specific page based on IP address for all cities
if (City.indexof ("Shanghai City") >=0) {
Window.location.href= "http://shanghai.demo.com/"; }
Put the section a code at the beginning and the C code above in the head and tail of the B-segment code, and then we add the following code to the page where we need to jump:
Refresh the page, is not to achieve the desired effect?
The above mentioned is the whole content of this article, I hope you can like.
http://www.bkjia.com/PHPjc/992547.html www.bkjia.com true http://www.bkjia.com/PHPjc/992547.html techarticle PHP Implementation based on the IP address to obtain the method of its province, the IP is located in the provinces and cities based on the existing IP address to obtain its geographical location (province, city, etc.) method function Getiplookup ($ip = ") {if (E ...