Generating random string in PHP: how to do it correctly and securely?
Hello everyone! I'm a beginner in PHP and writing a small website. I need to generate random strings for session tokens, temporary passwords, and link identifiers.
I found this code on the internet:
```php
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
```
But I'm concerned about several things:
1. The `rand()` function — I've heard it's not very random.
2. If I need 1000 strings, the script runs slowly.
3. I don't know if this is suitable for cryptographic purposes (tokens).
Can I use th