- rand: documentation ( source)
<?php
function apikey( $length ) {
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
$size = strlen( $chars );
$key ="";
for( $i = 0; $i < $length; $i++ ) {
$str= $chars[ rand( 0, $size - 1 ) ];
echo $str;
$key .= $str;
}
return $key;
}
$apikey = apikey(32);
echo "\noutside function\n";
echo $apikey;