使用php获取唯一系统ID

时间:2013-09-15 09:04:05

标签: php mysql

我希望客户端系统的唯一ID用于注册我的应用。

我的方法(或想法):

  1. 我在购买我的应用程序时向我的客户提供了一个密钥(key1

  2. 在我的本地服务器上安装我的应用程序后,我想验证该安装。所以他想提交表单

  3. 收到该信息后,我想存储该信息并更新其本地数据库。

    1. 我的服务器数据库'安装'表结构:名称(空),电子邮件(空),地址(空),key1,key2,unique_id(空),状态(0)

      if key1 currect and status == 0,他在unique_id中的信息保存在安装表&状态设置为1&他的本地数据库将使用key1和key2进行更新。

      if key1 currect and status == 1(重新安装时间),然后他的本地机器unique_id和安装表unique_id将检查。如果相等,他的本地数据库将使用key1和key2进行更新。

      if not currect,他的本地数据库将使用key1('key not valid')和key2('key not valid')进行更新。

  4. 如果本地数据库验证表值(key1和key2)不是'key not valid',则应用程序将起作用。

  5. 客户表格:

    <?php
    $unique_id = "i want unique system id here";
    ?>
    <form action="http://www.example.com/verifiy.php" method="post">
        <p>
            <label>Name</label>
            <input type="text" name="name" />
        </p>
        <p>
            <label>Email</label>
            <input type="text" name="email" />
        </p>
        <p>
            <label>Phone</label>
            <input type="text" name="phone" />
        </p>
        <p>
            <label>Activation key</label>
            <input type="text" name="name" />
        </p>
        <p class="hidden">
            <input type="text" name="unique_id" value="<?php echo $unique_id; ?>" />
        </p>
        <input type="submit" />
    </form>
    

    当客户提交此表单时,我希望在我的服务器上保存具有系统唯一ID的所有信息,我会给他一把钥匙。

    请帮助我,我如何获得客户端系统的唯一ID?对不起,我的英语不好。感谢。

3 个答案:

答案 0 :(得分:1)

您可以使用openssl_random_pseudo_bytesbin2hex获取安全的随机字符串。

echo bin2hex(openssl_random_pseudo_bytes(9));

答案 1 :(得分:0)

PHP 中使用uniqid功能。

<?php
/* A uniqid, like: 4b3403665fea6 */
printf("uniqid(): %s\r\n", uniqid());

您的代码..

<?php
$unique_id = uniqid(); // I have added it here.
?>
<form action="http://www.example.com/verifiy.php" method="post">
    <p>
        <label>Name</label>
        <input type="text" name="name" />
    </p>
    <p>
        <label>Email</label>
        <input type="text" name="email" />
    </p>
    <p>
        <label>Phone</label>
        <input type="text" name="phone" />
    </p>
    <p class="hidden">
        <input type="text" name="unique_id" value="<?php echo $unique_id; ?>" />
    </p>
    <input type="submit" />
</form>

答案 2 :(得分:0)

使用以下2个步骤生成有关访问者的唯一数据..

  1. 使用$ _SERVER ['REMOTE_ADDR']将为您提供正在查看此页面的用户的IP地址。

  2. 使用HTML5地理位置API获取用户的位置。

  3. 根据以上2个数据生成唯一ID

    <script>
       var x=document.getElementById("demo");
       function getLocation()
       {
         if (navigator.geolocation)
           {
             navigator.geolocation.getCurrentPosition(showPosition);
           }
         else{x.innerHTML="Geolocation is not supported by this browser.";}
       }
      function showPosition(position)
      {
       //Get latitude & longitude from position
       x.innerHTML="Latitude: " + position.coords.latitude + 
       "<br>Longitude: " + position.coords.longitude; 
       }
      </script>