2

我需要为访问我的网页的每个移动设备创建一个唯一的 ID。我已经获得了用户的屏幕分辨率、浏览器、操作系统和位置,但我还想知道运营商的名称以使其更准确。

到目前为止,我有:

<script type="text/javascript" language="Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" language="Javascript" src="http://api.easyjquery.com/easyjquery.js"></script>


<?PHP

$browsers = array ();
$osS = array ();
$tb_query=mysql_query("SELECT * FROM cst_unique_device_index"); 
while ($rw_query=mysql_fetch_array($tb_query)){
  extract ($rw_query);
  $variable = strtolower($variable); 

  if ($type == 2) $browsers[] = $variable;
}

$osS = array (
    "android",
    "bada",
    "blackberry",
    "brew",
    "ios",
    "lg",
    "linux",
    "motorola",
    "nintendo",
    "palm",
    "playstation",
    "samsung",
    "series",
    "sony",
    "symbianos",
    "unknown",
    "webos",
    "wince",
    "windows");


  $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
  foreach($browsers as $browser)
    {
    if (preg_match("#($browser)[/ ]?([0-9.]*)#", $agent, $matchBrowser))
      {
      $user_browser = $matchBrowser[1] ;
      $user_browser_version = $matchBrowser[2] ;
      break ;
      }
    }

  foreach($osS as $os)
    {
    if (preg_match("#($os)[/ ]?([a-z0-9.]*)#", $agent, $matchOS))
      {
      $user_os = $matchOS[1];
      $user_os_version = $matchBrowser[2] ;
      }
    }




echo $agent .'<br />'    ;
echo '
    <table>
      <tr>
        <th>Screen: </th>
        <td id="user_screen"></td>
        <td></td>
      </tr>
      <tr>
        <th>Browser: </th>
        <td>' . $user_browser . '</td>
        <td></td>
      </tr>
      <tr>
        <th>OS: </th>
        <td>' . $user_os . '</td>
        <td></td>
      </tr>
      <tr>
        <th>State: </th>
        <td id="user_state"></td>
        <td></td>
     </tr>
     <tr>
        <th>Carrier: </th>
        <td></td>
        <td></td>
      </tr>

    ';
?>


<script type="text/javascript" language="Javascript">
var screenWith = screen.width      
var screenHeight = screen.height

document.getElementById('user_screen').innerHTML = screenWith+"x"+screenHeight;


    // 1. Your Data Here
    function my_callback(json) {
        alert("IP :" + json.IP + " nCOUNTRY: " + json.COUNTRY);
    }

    function my_callback2(json) {
        // more information at http://api.easyjquery.com/test/demo-ip.php
        //alert("IP :" + json.IP + " nCOUNTRY: " + json.COUNTRY + " City: " +         json.cityName + " regionName: " + json.regionName);
        document.getElementById('user_state').innerHTML = json.cityName;
    }

    // 2. Setup Callback Function
   // EasyjQuery_Get_IP("my_callback"); // fastest version
    EasyjQuery_Get_IP("my_callback2","full"); // full version


</script>
4

2 回答 2

2

如果你能直接得到它,那将是一个安全问题。浏览器在沙箱中运行,应该无法获取该数据。

您可以记录 IP 地址并查找每个运营商的范围。我认为这将是一个聪明的猜测。

您可以从例如http://whois.arin.net/ui获取它们

AT&T
32.0.0.0 - 32.255.255.255 
166.128.0.0 - 166.255.255.255 
于 2012-06-25T17:59:44.807 回答
0

您可以从 IP 地址获取用户运营商名称。

<?php
$ip = $_REQUEST['REMOTE_ADDR']; // the IP address to query
$query = @unserialize(file_get_contents('http://ip-
api.com/php/'.$ip));
if($query && $query['status'] == 'success') {
  echo 'Hello visitor from '.$query['country'].', '.$query['city'].'!';
} else {
  echo 'Unable to get location';
}
?>

这对我有用,我希望也对你有用。:)

于 2017-04-17T07:16:44.453 回答