I would like to create a random string of 25 alpha-numerical characters that when ran via a cron, would print the results to a key.txt file.
What would be the best way to do it? Thank you.
I would like to create a random string of 25 alpha-numerical characters that when ran via a cron, would print the results to a key.txt file.
What would be the best way to do it? Thank you.
There are tons of tutorials out there, one possible solution (for a learning purpose, that is) would be:
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
// alternatively: implode('', array_merge(range(0,9),range('a', 'z'), range('A', 'Z')));
$length = 25;
$string = '';
for ($i = 0; $i < $length; $i++)
$string .= $chars[rand(0, strlen($chars) - 1)];
// save it to a file
file_put_contents("key.txt", $string);