Doug:
This is a function I use to get a unique id for my shopping cart program. I found this script originally at: www.webtechniques.com/archives/2000/11/junk/
and it was done by Ray Argus and Jedid Freeland. I am not the creator of this function, but find it quite useful.
In the article at the URL above they explain the script in more detail.
//This function gets a unique order number
//Text file ctr.lock must be in default directory
function uniqueID($fn) {
// lock a file
$ctl = fopen($fn . ".LOCK","a+");
flock($ctl,2);
// open the target file
$ct=fopen($fn,"r");
// get the count
if (!$ct) {
$n=0;
}
else
{
$s=fgets($ct,16);
$n=$s+1;
fclose($ct);
}
$ct=fopen($fn,"w");
// update count
fputs($ct,$n);
fclose($ct);
// release lock
flock($ctl,3);
fclose($ctl);
return $n;
}
I call the function using this line:
$ioc_merchant_order_id = date("my-") . sprintf("%04d",uniqueID("ctr"));
This provides me a customer number that starts with the month/year (1200) and then a dash and then a unique number provided by the function. For example 1200-0257.
In the text file that the function reads you can set the starting number to whatever you like and of course you can format the returned number in any manner. So you could have a unique id that reads 1200-12457.
Good Luck
Bruce