This is my situation.
I have designed an online questionnaire, as a reward for filling in the questionnaire there are entitled to a discount when they attend an event.
Any ideas on how I might go about generating a unique id for each person that fills in the questionnaire.
I was thinking of using their firstname then autoincrement the end thus: andrew01 and so on.
The problem with this is that people might but spaces or funny characters in their first name. Thus I was thinking it might be better to generate a random string of alpha characters and then auto increment the end.
Like SDFSFF01, SDFPPF02 And on on.
Any help with the code would be most excellent. But if you have a better solution then I'd be thankful to hear your ideas.
Andi
creating unique id.
Moderator: General Moderators
you could use the rand function seeded by the unix timestamp...
Code: Select all
srand(time());
$id = rand();-
sillywilly
- Forum Newbie
- Posts: 19
- Joined: Thu May 02, 2002 5:11 pm
as i understand it, would be completely unique but i suppose there is a remote possibility that if 2 people come at exactly the same time and php makes the same random number out of that time it wouldn't be. there are of course other ways to get a unique id type thing...looking them up i came across another i hadn't used before but if you don't want to have just numbers, you could use uniqueid or you could prepend it with something can find out about it at http://www.php.net/manual/en/function.uniqid.php and you can get really complicated stuff with
hth.
Code: Select all
$uniq_id = uniqid("");
// Some 13 character value such as ' 39b3209ce8ef2' will be generated.Code: Select all
$uniq_id = uniqid("uid", TRUE);
// Some value such as 'uid39b3209ce8ef2' will be generated.Code: Select all
srand ((double) microtime() * 1000000);
$uniq_id = uniqid(rand());-
sillywilly
- Forum Newbie
- Posts: 19
- Joined: Thu May 02, 2002 5:11 pm
HI there,
Thank you for your help. I decided to use:
but the value generated is:
gamemore3d11f0c1d11506.65157377
Do you know why i'm getting the ".65157377"
Thank you for your help. I decided to use:
Code: Select all
$uniq_id = uniqid("uid", TRUE);
// Some value such as 'uid39b3209ce8ef2' will be generated.gamemore3d11f0c1d11506.65157377
Do you know why i'm getting the ".65157377"