Hello Every one I have a problem in my website that i want to generate the user ids like 0u3012ewd0 as we see on many sites but don't have any idea how to do this.

Please help me in this problem

Thanks alot.

No one is here to help Me :(

How I would do it

<?
$stringlen = 15;
$randvarray = str_split("abcdefghijklmnopqrstuvwxyz0123456789");
$stringid = "";

for($i = 0; $i < $stringlen; $i++)
{
	$value = rand(0, count($randvarray) - 1);
	$stringid .= $randvarray[$value];
}

echo $stringid;
?>
commented: Great Post +1

Thanks alot R0bb0b

No Problem.

Thought I'd add another example:

/**
* Returns a random Alpha-Numeric string
 * @param Int $len Length of string to return
 * @return Str
 */
function randAlpha($len = 15) {
	$str = '';
	for($i = 0; $i < $len; $i++) {
		$rand = rand()%36;
		$str .= chr($rand > 10 ? $rand%26+97 : $rand%10+48);
	}
	return $str;
}

The resulting alpha-numeric chars won't be as evenly distributed as R0bb0b's example since rand() will use the range of 0-RAND_MAX, but just another way at it.

thanks alot you guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.