Jump to content

[SOLVED] MT_Rand function duplicating ticket id's


chrispols

Recommended Posts

Hi there,

 

I've been running Epix Power support ticketing system for a few months now and it's been working very well. Recently however, it's started to duplicate the ticket id's. So from a ticket entered a few months back, someone entering a new ticket would put their information on that original ticket. This obviously is not good for a support site.

 

The code that is running the generation of the number is the following:

for($id=0; $id<10; $id++){
		$p_id .= substr("ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789", mt_rand(1,35), 1);	//Randomize Ticket ID
	}

 

Is there a way to make the generation of that ID more random than it is now? If there is, how would I go about doing it?

 

Thanks a lot,

 

Chris

  • 2 weeks later...

Ok, no response from making it more Random. How would I go about adding the time into the ticket id?

 

I reckon something like this:

 

$p_id .= substr("ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789", mt_rand(1,35), 1)(TIME);	//Randomize Ticket ID

 

So this would definitely give a unique ID as the time (i.e. 1209 - 12:09) can be added to the end of the so called "Random mt_rand" function.

 

Is this viable?

Thanks

Chris

Your second post, I think, begins to see the issue. You want more order, not more chaos (randomness).

I'd do it like this:

<?
$dt=date(Ymd)
// or $dt=date(ymdHis); 
// see http://www.tizag.com/phpT/phpdate.php for more options
$p_id .= substr("ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789", mt_rand(1,35), 1).$dt;
?>

Hey TecBrat,

 

Awesome, that's got me on the right track. Here's my final code:

	$dt=date(Hi);
	$p_id = "".$dt;
	for($id=0; $id<4; $id++){
		$p_id .= substr("ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789", mt_rand(1,35), 1);
	}

I made it : date(Hi) with 4 subsequent substr.. this should make it impossible to duplicate in theory. If we had 100 tickets inputted the same day with the date in the beginning, we could experience the duplication, but having the time there it should be unique.

 

Thanks for the advice, brilliant!

Chris

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.