-1

I am trying to generate support tickets for my website support option. I won't be using much features with the support system. I just want that the generated ticket ID numbers to not be repeated. What I tried gave me '0' two times in my database and single digits sometimes.

What I want is that whenever a new ticket is generated it should have consistent number of digits and never to repeat again.

The following is my code which I am using:

   $token = openssl_random_pseudo_bytes(16);
   $ticket = bin2hex($token);

Please guide me a better way.

Matt S
  • 14,976
  • 6
  • 57
  • 76
Ayan
  • 2,738
  • 3
  • 35
  • 76
  • Can't you just use a normal auto_increment? – Manikiran Apr 12 '16 at 17:21
  • You don't do that by using a random number. With a random you _obviously_ cannot make any predictions about the sequence. Instead you use the features builtin to the database. Either some `auto increment` like MySQL offer it or some key generator as used in other relational database systems. – arkascha Apr 12 '16 at 17:23
  • 1
    @ayan Chill dude, you can easily do it without any coding in php. Just execute this mysql statement. `ALTER TABLE tokens AUTO_INCREMENT = 100000;` – Manikiran Apr 12 '16 at 17:31
  • @Manikiran I feel this is better. Actually I had no clear conception of how tokens were generated – Ayan Apr 12 '16 at 17:44
  • By the way can anyone tell me what was so bad in my question that it got 2 downvotes? – Ayan Apr 12 '16 at 17:45
  • 2
    @Ayan there are some kind of questions, when giving too much information about a problem is harmful. If you'd ask how to generate a non-repeating pseudo-random sequence of numbers and could show an example of what you've done yourself, plus provided some links to similar questions - you could get some upvotes. *Disclaimer: I didn't vote* P.S.: Haters Gonna Hate – Axalix Apr 12 '16 at 19:10
  • @Axalix, well haters didn't see that I did showed what I have done on my own. Anyway thanks for the insight about the downvotes. – Ayan Apr 13 '16 at 08:13

1 Answers1

-2

What kind of database are you using?

Use auto-increment to create unique ID's for your tickets. MySql has an item about his here

JKMurray
  • 37
  • 3