Page 1 of 1

random id numbers

Posted: Thu Aug 31, 2006 7:37 am
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

Posted: Thu Aug 31, 2006 7:52 am
by CoderGoblin
string uniqid ( [string prefix [, bool more_entropy]] ) may be useful.

Although isn't that javascript you are using rather than php?

Posted: Thu Aug 31, 2006 7:53 am
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?

Posted: Thu Aug 31, 2006 7:58 am
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