Page 1 of 1

creating unique id.

Posted: Wed Jun 19, 2002 11:27 am
by sillywilly
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

Posted: Wed Jun 19, 2002 12:34 pm
by kaizix
you could use the rand function seeded by the unix timestamp...

Code: Select all

srand(time());
$id = rand();

Posted: Wed Jun 19, 2002 1:49 pm
by sillywilly
Will this create a totally unique id? As in no one id will ever be the same? Also what do you suggest i set the database row to int(30)?

Posted: Wed Jun 19, 2002 2:18 pm
by kaizix
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

Code: Select all

$uniq_id = uniqid("");
 // Some 13 character value such as ' 39b3209ce8ef2' will be generated.
or you could prepend it with something

Code: Select all

$uniq_id = uniqid("uid", TRUE);
// Some value such as 'uid39b3209ce8ef2' will be generated.
can find out about it at http://www.php.net/manual/en/function.uniqid.php and you can get really complicated stuff with

Code: Select all

srand ((double) microtime() * 1000000);
$uniq_id = uniqid(rand());
hth.

Posted: Thu Jun 20, 2002 10:15 am
by sillywilly
HI there,

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.
but the value generated is:

gamemore3d11f0c1d11506.65157377

Do you know why i'm getting the ".65157377"

Posted: Thu Jun 20, 2002 3:31 pm
by kaizix
is it adding that to it each time? the same thing or different each time?