Generate unique n-digit random alphanumeric codes?

Syntax

uniqid (prefix, more_entropy);

 

A unique website ID can be created in PHP using the uniqid () function.

This function has two parameters that can be set.

 

prefix

This is what will be appended to the beginning of each ID.

 

more_entropy

If this is false or not specified it will return 13 characters, if it is true then 23 characters will be returned.

 

Below are some examples:

[php]

<?php

/*creates a unique id with the ‘sa’ prefix*/
$a = uniqid(sa); echo $a; echo "<br />";

/*creates a longer unique id with the ‘sa’ prefix*/
$b = uniqid (sa, true); echo $b; echo "<br />";

/*creates a unique ID with a random number as a prefix – this is more secure than a static prefix*/
$c = uniqid (rand (),true); echo $c; echo "<br />";

/*this md5 encrypts the username from above, so its ready to be stored in your database*/
$md5c = md5($c); echo $md5c;

?>

[/php]

5 thoughts on “Generate unique n-digit random alphanumeric codes?”

  1. Wow, marvelous blog structure! How long have you ever been
    running a blog for? you make blogging glance easy. The entire look of your web site is magnificent, as well as the
    content!

  2. Great beat ! I would like to apprentice while you amend your site,
    how could i subscribe for a blog website? The account aided me a acceptable deal.
    I had been tiny bit acquainted of this your broadcast offered bright clear concept

  3. Very nice post. I just stumbled upon your weblog and wished to say that.
    I’ve truly enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!

  4. It’s great that you are getting ideas from this paragraph as well as from our argument made here.

Comments are closed.