note 128317 added to function.rand
| From: | play dot it at play-it dot net | Date: | Fri, 17 Mar 2023 13:49:22 +0000 |
| Subject: | note 128317 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220274@lists.php.net to get a copy of this message | ||
Here is a simple base64 random string function
<?php
function random_string($length) {
$str = random_bytes($length);
$str = base64_encode($str);
$str = str_replace(["+", "/", "="], "", $str);
$str = substr($str, 0, $length);
return $str;
}
/*
Example outputs for random_string(32)
OP0vOJEsSvr6wbgN4jIwqMMstlpMSUsl
2IHaIxD2W4VTKZuzioudbpQCALdl6Ym6
QY0eZ3QYy3OKKN6ttzbDwAwsAfkXfQ2f
jznjlPCUDbYzOTJysPP414BbdVNu4jmT
GlktgJ8JUhdH5MfQ1PHl0wnqXQlKggQs
Pb9WALM3KcGCCPBKXsPgNfy3M0Xj4aEu
AED6OTVl8aBbspdxoXvA1sT4ein8lruH
9cSbz4FhoI4qSsPZFMh0u1rWDDEgQxI2
iSBlT4K7Ad516qPXgPReSj2tii7TAK5b
DuX8HByMb2e8IdM4j49Td2JTI9Ki7o1C
*/
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 84.60.216.22)
----
Manual Page -- https://php.net/manual/en/function.rand.php
Edit -- https://main.php.net/note/edit/128317
Del: integrated -- https://main.php.net/note/delete/128317/integrated
Del: useless -- https://main.php.net/note/delete/128317/useless
Del: bad code -- https://main.php.net/note/delete/128317/bad+code
Del: spam -- https://main.php.net/note/delete/128317/spam
Del: non-english -- https://main.php.net/note/delete/128317/non-english
Del: in docs -- https://main.php.net/note/delete/128317/in+docs
Del: other reasons-- https://main.php.net/note/delete/128317
Reject -- https://main.php.net/note/reject/128317
Search -- https://main.php.net/manage/user-notes.php