phpCopy<?php
$Random_str = uniqid();
echo "Random String:", $Random_str, "\n";
?>
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
Output the random string with the call below:
// Echo the random string.
// Optionally, you can give it a desired string length.
echo generateRandomString();
phpCopy<?php
echo "Out1: ",substr(md5(time()), 0, 16),"\n";
echo "Out2: ",substr(sha1(time()), 0, 16),"\n";
echo "Out3: ",md5(time()),"\n";
echo "Out4: ",sha1(time()),"\n";
?>