php生成唯一id_如何在PHP中生成唯一ID

php生成唯一id

A unique user ID can be created in PHP using the uniqid () function. This function has two parameters you can set.

可以使用uniqid()函数在PHP中创建唯一的用户ID。 此功能有两个参数可以设置。

The first is the prefix, which is what will be appended to the beginning of each ID. The second is more_entropy. If this is false or not specified, it will return 13 characters; if it's true, 23 characters will be returned.

第一个是前缀,这是将添加到每个ID开头的前缀。 第二个是more_entropy。 如果为false或未指定,则将返回13个字符;否则为false。 如果为true,则将返回23个字符。

创建唯一ID的示例 ( Examples For Creating a Unique ID )

Below are examples of creating a unique user ID, but each are a little different.

以下是创建唯一用户ID的示例,但每个示例都有一些不同。

The first creates a normal unique ID while the second shows how to make a longer ID. The third example creates an ID with a random number as the prefix while the last line can be used to encrypt the username before storing it.

第一个创建普通的唯一ID,第二个显示如何制作更长的ID。 第三个示例创建一个以随机数作为前缀的ID,而最后一行可在存储用户名之前用于加密用户名。


//creates a unique id with the 'about' prefix $a = uniqid(about); echo $a; echo "


//creates a longer unique id with the 'about' prefix $b = uniqid (about, true); Echo $b; echo "


//creates a unique ID with a random number as a prefix - more secure than a static prefix $c = uniqid (rand (),true); echo $c; echo "


//this md5 encrypts the username from above, so its ready to be stored in your database $md5c = md5($c); e

翻译自: https://www.thoughtco.com/how-to-generate-unique-id-2694169

php生成唯一id

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值