creating unique id.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sillywilly
Forum Newbie
Posts: 19
Joined: Thu May 02, 2002 5:11 pm

creating unique id.

Post 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
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post by kaizix »

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

Post 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)?
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post 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.
sillywilly
Forum Newbie
Posts: 19
Joined: Thu May 02, 2002 5:11 pm

Post 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"
kaizix
Forum Commoner
Posts: 50
Joined: Tue Jun 18, 2002 9:16 pm
Location: california
Contact:

Post by kaizix »

is it adding that to it each time? the same thing or different each time?
Post Reply