Home » Php » Advance Php Interview Question » Generate random unique string in php

Generate random unique string in php

Generate random unique string, using letters and numbers

To generate a random unique string, using letters and numbers, For using to verifay a regsitration confurmation link and forgot password link.
Example: When you create an account on a website, it sends an email to your email id with a link, and you have to click that link in order to verify your account.this link have a unique token number which is one time used after that it’s expired.

In PHP, you can use uniqid() function.This function generates a unique ID based on the microtime, it give 13 charecter long string if you pass true as second parameter it give 23 charecter string.

To produces a better random value you can add random prefix:

But This is not a secure method of generating random values. so we have generate token in another ways this is a best and professional way to generate random string in php.

, , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">