random id numbers

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
mjaywoods
Forum Newbie
Posts: 11
Joined: Wed Jul 12, 2006 9:32 am

random id numbers

Post by mjaywoods »

I am building a large website in php which as many forms to fill in and i need to set a id number field that is unique for each form if i use this code

Code: Select all

function resetDynamicFields()
{
	document.placeform.OrderId.value=Math.round(Math.random()*10000000000);
}
what is the chances of me getting to of the same numbers coming up. Even if its one in a million i can't take them chances as it would be getting a very lot of traffic

edit: is there away to do this without javascript?


thx mjay
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

string uniqid ( [string prefix [, bool more_entropy]] ) may be useful.

Although isn't that javascript you are using rather than php?
Last edited by CoderGoblin on Thu Aug 31, 2006 7:53 am, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

That doesn't look like php code but javascript -> viewforum.php?f=13

It only needs to be unique within the document? Then why not simply use a counter?
mjaywoods
Forum Newbie
Posts: 11
Joined: Wed Jul 12, 2006 9:32 am

Post by mjaywoods »

Thanks CoderGoblin that should do the trick. i needed a unique id for each form as there are around 6 pages long so once the first page is submitted i need away of tracking the record inputted for the next pages. Having a unique id seems like the easyest way as long as the id is unique and not gonna be repeated.

mjay
Post Reply