JS access to client IP and location __js

Source: Internet
Author: User
Tags explode

PHP Capture Method:

1.<?php 
2.function get_ip_place () { 
3. $ip =file_get_contents ("http://fw.qq.com/ipaddress");   
4. $ip =str_replace (' ",", $IP);   
5. $ip 2=explode ("(", $IP);   
6. $a =substr ($ip 2[1],0,-2);   
7. $b =explode (",", $a);   
8.return $b;   
9.}   
$ip =get_ip_place ();   
11.print_r ($IP); 
12.? > 


JS get

Demo:http://blog.suiyidian.cn/texiao/ipd.html

Tencent's IP Address API interface address: http://fw.qq.com/ipaddress
The data format returned is: var ipdata = new Array ("114.218.183.139″," "," "Beijing");
Use JS code to make a fetch:

<script language= "javascript" type= "Text/javascript" src= "http://fw.qq.com/ipaddress" >
</script>
 <script>document.write ("Your IP is:" +ipdata[0]+ ", From:" +ipdata[2]);
</script> 


Tencent IP, turn UTF-8:

<script type= "Text/javascript" src= "http://fw.qq.com/ipaddress" charset= "gb2312" ></script>

$ ( Document). Ready (function () {

	$ ("#ip"). Val (ipdata[0]);
	$ ("#add"). Val (ipdata[2]);
}


Other ways to get:

Sina's IP address query interface: HTTP://INT.DPOOL.SINA.COM.CN/IPLOOKUP/IPLOOKUP.PHP?FORMAT=JS
Sina Multi-Region test method: http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=12.130.132.30
Sohu IP Address Query interface (default GBK): Http://pv.sohu.com/cityjson
Sohu IP Address Query interface (can be set code): Http://pv.sohu.com/cityjson?ie=utf-8
Sohu additional IP Address query interface: HTTP://TXT.GO.SOHU.COM/IP/SOIP

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.