ip
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>t1</title>
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
<style> /* css reset */
body,p,ol,ul,li,dl,dd,h1,h2,h3,h4,h5,h6,input,iframe,nav,header,footer { margin: 0; padding: 0; list-style: none; } body { font: 16px Microsoft YaHei, sans-serif; color: #2a2b2c; background: #fff; }
a,img { text-decoration: none; color: #2a2b2c; border: 0; } *, *::before, *::after { outline: none; box-sizing: border-box; } .xxx-btn { display: block; width: 100px; height: 38px; font: 16px/38px Microsoft YaHei; color: #fff; background: #0cf; border: 0; cursor: pointer; text-align: center; border-radius: 2px; box-shadow: 0 1px 5px #bbb; opacity: .8; transition: .5s; } .xxx-btn:hover { opacity: 1; box-shadow: 0 1px 10px #aaa; }
</style>
</head>
<body>
<h1>点击获取ip</h1>
<br>
<button class="xxx-btn" onclick="aa()">click me</button>
<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
<script>
function aa() {
alert(returnCitySN['cip'] + returnCitySN['cname']);
// echo (returnCitySN['cip'] + returnCitySN['cname']);
// alert(returnCitySN['cname']);
// alert(returnCitySN['cip']);
};
</script>
<FORM METHOD=get ACTION="http://www.ip138.com/ips1388.asp" name="ipform" target="_blank">
<tr><td align="center">IP地址:<input type="text" name="ip" size="16">
<input type="submit" value="查询"><INPUT TYPE="hidden" name="action" value="2">
</td></tr></FORM>
</body>
</html>
-------------------------------------------------------------------------------------------------------------
<?php//这个类似用来获取访客信息的//方便统计class visitorInfo{ //获取访客ip public function getIp() { $ip=false; if(!empty($_SERVER["HTTP_CLIENT_IP"])){ $ip = $_SERVER["HTTP_CLIENT_IP"]; } if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']); if ($ip) { array_unshift($ips, $ip); $ip = FALSE; } for ($i = 0; $i < count($ips); $i++) { if (!eregi ("^(10│172.16│192.168).", $ips[$i])) { $ip = $ips[$i]; break; } } } return ($ip ? $ip : $_SERVER['REMOTE_ADDR']); } //根据ip获取城市、网络运营商等信息 public function findCityByIp($ip){ $data = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$ip); return json_decode($data,$assoc=true); } //获取用户浏览器类型 public function getBrowser(){ $agent=$_SERVER["HTTP_USER_AGENT"]; if(strpos($agent,'MSIE')!==false || strpos($agent,'rv:11.0')) //ie11判断 return "ie"; else if(strpos($agent,'Firefox')!==false) return "firefox"; else if(strpos($agent,'Chrome')!==false) return "chrome"; else if(strpos($agent,'Opera')!==false) return 'opera'; else if((strpos($agent,'Chrome')==false)&&strpos($agent,'Safari')!==false) return 'safari'; else return 'unknown'; } //获取网站来源 public function getFromPage(){ return $_SERVER['HTTP_REFERER']; }}

浙公网安备 33010602011771号