问题描述
如何使用数字和字母生成一个随机,唯一的字符串以用于验证链接?就像您在网站上创建帐户一样,它会向您发送一封包含链接的电子邮件,您必须单击该链接才能验证您的帐户...是的...其中之一.
How would it be possible to generate a random, unique string using numbers and letters for use in a verify link? Like when you create an account on a website, and it sends you an email with a link, and you have to click that link in order to verify your account...yeah...one of those.
如何使用PHP生成其中之一?
How can I generate one of those using PHP?
更新:刚刚记得有关 uniqid()
的内容.这是一个PHP函数,它根据当前时间(以微秒为单位)生成唯一的标识符.我想我会用.
Update: Just remembered about uniqid()
. It's a PHP function that generates a unique identifier based on the current time in microseconds. I think I'll use that.
推荐答案
如果您不希望它随着时间的流逝而变得绝对独特:
If you do not need it to be absolutely unique over time:
md5(uniqid(rand(), true))
否则(假设您已经为用户确定了唯一的登录名):
Otherwise (given you have already determined a unique login for your user):
md5(uniqid($your_user_login, true))
这篇关于PHP:如何生成一个随机的,唯一的字母数字字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!