I am using the following PHP to generate a few (usually 3) random strings and place them in session variables to use as controls.
function session_var($type) {
if ( !isset ( $_SESSION[$type] ) ) {
$_SESSION[$type] = rand_string( 5 );
}
}
function rand_string( $length ) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$size = strlen( $chars );
$str = '';
for( $i = 0; $i < $length; $i++ ) {
$str .= $chars[ rand( 0, $size - 1 ) ];
}
return ($str);
}
How do I eliminate the rare occasion where the same random string might be generated more than once in the same session? I don’t want any of the session variables to be the same.
Thanks