Creating a random string in PHP

Here’s a very useful function to generate a random string in php. I use this function quite often especially while working in core php projects.

function create_random_string($length=9)	{
	$salt = "abTUcdeIMNfjkl2m345noRqJKLr0s7tuvw1xyzABCD68EFGHpOPQSVWghiXYZ9".time();
	while( $i <= $length )
	$num = rand()%33 ;
	$new = substr($salt,$num,1);
	$res = $res.$new;
	return $res;

Leave a Reply

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