当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > uniqid() 函数

PHP
WINDOWS下安装MySQL
PHP 制作 网站/服务器 监视脚本
用PHP和CSS制作活动按钮
PHP 单件模式
PHP MVC模式,类封装以及HACK
PHP 中使用正则表达式
PHP 防止 SQL 注入攻击
PHP 跨站点脚本攻击
PHP 防止用户操纵 GET 变量
PHP 防止远程表单提交

PHP 中的 uniqid() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 502 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The uniqid() function generates a unique ID based on the microtime (current time in microseconds).
uniqid()函数的作用是:产生一个基于系统时间的独立ID(当前时间以微秒为单位)。

Syntax
语法

uniqid(prefix,more_entropy)
 
Parameter参数 Description描述
prefix Optional. Specifies a prefix to the unique ID (useful if two scripts generate ids at exactly the same microsecond)
可选参数。指定一个独立id的前缀(如果两个脚本同时产生两个id(单位:微秒),那么,这个参数就非常有用)

Note: This parameter became optional in PHP 5
注意:这个参数在PHP 5中是可选参数

more_entropy Optional. Specifies more entropy at the end of the return value. This will make the result more unique. When set to TRUE, the return string will be 23 characters. Default is FALSE, and the return string will be 13 characters long
可选参数。在返回值的末尾指定多个随机计量单位。它将是返回的结果变成独一无二的。如果将其设置为True时,它将返回23个字符;如果将其设置为False时,它将返回13个字符。默认是False。


Tips and Notes
注意点

Note: The generated ID from this function is not optimal, because it is based on the system time. To generate an extremely difficult to predict ID, use the md5() function (can be found in the String reference).
注意:通过uniqid()函数所产生的ID不是最理想的,因为它是基于系统时间产生的。如果你想获取一个极难预知的id,你可以使用md5()函数(可以在“PHP字符串函数”中找到相关的内容)。


Example
案例

<?php
echo uniqid();
?> 

The output of the code above could be:
上述代码将输出下面的结果:

4415297e3af8c

评论 (0) All

登陆 | 还没注册?