如何在 php 5.2 中为每个用户(会话?)创建真正的唯一编号

发布于 2024-10-05 22:29:25 字数 92 浏览 0 评论 0原文

如果我想为每个用户创建真正安全(多线程安全)的唯一编号,我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鼻尖触碰 2024-10-12 22:29:25

当用户访问该页面时,被分配给唯一的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 before session_start().
using »» session_id()

Take a look at the manual »» http://www.php.net/manual/en/ref.session.php

Good Luck

凡尘雨 2024-10-12 22:29:25

这取决于:

如果您想要的是每个用户的编号,您将希望数据库自动增量(或者如果不支持,则手动执行)一个唯一的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文