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 ?
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
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.
精彩评论