Introduction: This is a detailed page for PHP to obtain information about the IP address of a user. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 340860 'scrolling = 'no'> recently, information about the location of the user's IP address is used in the project, mainly to identify the city where the user is located from the IP address, currently, there are several types of city information that are associated with the city by ID number, and the abbreviationCode. We use IP addresses to obtain detailed information about the user's city, for example, if the following result is run, "Fuzhou Telecom, Fujian Province" can get the user's province, city, and network access information. Here, Baidu's open query interface is called, query through the web page and then match the information we need from the returned results. The effect is good. The code is below and can still be used together.
Var_dump (getaddress ('192. 101.98.54 ', 'fuzhou'); function getaddress ($ IP = NULL, $ address = '') {$ url =" http://open.baidu.com/ipsearch/s? WD = {$ IP} & Tn = baiduip "; $ res = mb_convert_encoding (httprequest ($ URL), 'utf-8', 'gbk '); // var_dump ($ res); If (preg_match ('# From: <B> (. +) </B> # UI ', $ res, $ m) {If (is_int (strpos ($ M [1], $ address ))) {return $ M [1] ;}} function httprequest ($ URL, $ DATA = array () {$ CH = curl_init (); If (is_array ($ data) & $ data) {$ formdata = http_build_query ($ data); curl_setopt ($ ch, curlopt_post, true); curl_setopt ($ ch, curlopt_postfields, $ formdata );} curl_setopt ($ ch, curlopt_url, $ URL); curl_setopt ($ ch, success, true); curl_setopt ($ ch, curlopt_connecttimeout, 2); curl_setopt ($ ch, curlopt_timeout, 2); Return curl_exec ($ ch );}
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/340860.html pageno: 7.