PHP obtains information about the IP address of a user.

Source: Internet
Author: User

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.

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.