php - Creating random character unique URLS -
how generate random 12 character char url of page record in database how youtube 11 characters https://www.youtube.com/watch?v=kdjirnjcanw
i want unique each entry in database , consist of letters of upper , lower case, numbers , maybe (if not bad security) special characters.
function:
function generaterandomstring($length = 12) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'; $characterslength = strlen($characters); $randomstring = ''; ($i = 0; $i < $length; $i++) { $randomstring .= $characters[rand(0, $characterslength - 1)]; } return $randomstring; }
then call it:
$randomstring = generaterandomstring();
Comments
Post a Comment