如何在 php 5.2 中为每个用户(会话?)创建真正的唯一编号
如果我想为每个用户创建真正安全(多线程安全)的唯一编号,我是 php 新手 当他创建文件时,文件名将从唯一的名称构建,我猜它将从唯一的字符串构建。 最好的方法是什么?
Im new to php if I like to create true safe ( multithread safe ) unique number for each user
when he create a file , the file name will be build from unique name , that i guess will construct from unique string.
What is the best way to do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当用户访问该页面时,被分配给唯一的id,它被称为session_id。
如果您想处理您的
session_id
,您需要在session_start()
之前设置它。使用 »»
session_id()
查看手册 »» http://www.php.net/manual/en/ref.session.php
祝你好运
when the user access the page, is assigned to unique id, it is called session_id.
If you want to handle your
session_id
, you need to set it beforesession_start()
.using »»
session_id()
Take a look at the manual »» http://www.php.net/manual/en/ref.session.php
Good Luck
这取决于:
如果您想要的是每个用户的编号,您将希望数据库自动增量(或者如果不支持,则手动执行)一个唯一的 ID。
如果您想要会话的唯一 ID,而不是特定的用户。然后您可以在用户登录后将其绑定到用户。您可以使用 PHP 会话。他们用来选择用户的哈希将生成一个当前未使用的唯一 ID。这已经足够好了。然后,当用户登录时,您将数据库中的唯一 ID 添加到会话中。
现在您的用户和会话已绑定在一起。
It depends:
If what you want is a number for each user, you'll want to have your database auto_increment (or if that isn't supported, do it manually) a unique ID.
If you want a unique ID for the session, and not the user specifically. Which you can then tie to the user after they log in. You can use PHP Sessions. The hash they use to select a user will produce a unique ID that isn't currently in use. Which is good enough. Then, when the user logs in, you add to the session the unique ID from the database.
Now your user and session are tied together.