获取访问地址 的IP地址信息:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>

 <head>

  <meta http-equiv="content-type" content="text/html;charset=utf-8">

  <title>javascript获取访问者IP及所在地</title>

  <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>

 </head>

 

 <body>

  <script type="text/javascript">

    document.write("IP: " + returnCitySN['cip'] + "<br>地区代码: " + returnCitySN['cid'] + "<br>所在地: " + returnCitySN['cname']);  </script>

 </body></html

获取访问者的设备信息

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

 <head>

  <meta http-equiv="content-type" content="text/html;charset=utf-8">

  <title>javascript获取访问者设备信息</title>

 </head>

 

 <body>

  <script type="text/javascript">

    document.write("userAgent: " + navigator.userAgent + "<br><br>");

    document.write("appName: " + navigator.appName + "<br><br>");

    document.write("appCodeName: " + navigator.appCodeName + "<br><br>");

    document.write("appVersion: " + navigator.appVersion + "<br><br>");

    document.write("appMinorVersion: " + navigator.appMinorVersion + "<br><br>");

    document.write("platform: " + navigator.platform + "<br><br>");

    document.write("cookieEnabled: " + navigator.cookieEnabled + "<br><br>");

    document.write("onLine: " + navigator.onLine + "<br><br>");

    document.write("userLanguage: " + navigator.language + "<br><br>");

    document.write("mimeTypes.description: " + navigator.mimeTypes[1].description + "<br><br>");

    document.write("mimeTypes.type: " + navigator.mimeTypes[1].type + "<br><br>");

    document.write("plugins.description: " + navigator.plugins[3].description + "<br><br>");

  </script>

 </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'];
 }

}