chrispols Posted March 14, 2007 Share Posted March 14, 2007 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 Link to comment https://forums.phpfreaks.com/topic/42640-solved-mt_rand-function-duplicating-ticket-ids/ Share on other sites More sharing options...
chrispols Posted March 22, 2007 Author Share Posted March 22, 2007 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 Link to comment https://forums.phpfreaks.com/topic/42640-solved-mt_rand-function-duplicating-ticket-ids/#findComment-212671 Share on other sites More sharing options...
TecBrat Posted March 22, 2007 Share Posted March 22, 2007 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; ?> Link to comment https://forums.phpfreaks.com/topic/42640-solved-mt_rand-function-duplicating-ticket-ids/#findComment-212711 Share on other sites More sharing options...
chrispols Posted March 22, 2007 Author Share Posted March 22, 2007 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 Link to comment https://forums.phpfreaks.com/topic/42640-solved-mt_rand-function-duplicating-ticket-ids/#findComment-212745 Share on other sites More sharing options...
Orio Posted March 22, 2007 Share Posted March 22, 2007 If you want to make it even more random, use str_shuffle: $p_id .= substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"), mt_rand(1,35), 1); Orio. Link to comment https://forums.phpfreaks.com/topic/42640-solved-mt_rand-function-duplicating-ticket-ids/#findComment-212746 Share on other sites More sharing options...
mjlogan Posted March 22, 2007 Share Posted March 22, 2007 strtoupper(md5(time())); Link to comment https://forums.phpfreaks.com/topic/42640-solved-mt_rand-function-duplicating-ticket-ids/#findComment-212748 Share on other sites More sharing options...
TecBrat Posted March 23, 2007 Share Posted March 23, 2007 Hey TecBrat, Awesome, that's got me on the right track... You're welcome. Glad to help. Link to comment https://forums.phpfreaks.com/topic/42640-solved-mt_rand-function-duplicating-ticket-ids/#findComment-213165 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.