=5.3 and <7 if(function_exists('openssl_random_pseudo_bytes')) { $token = base64_encode(openssl_random_pseudo_bytes($length, $strong)); // is the token strong enough? if($strong == true) return strtr(substr($token, 0, $length), '+/=', '-_,'); } //fallback to mt_rand if php < 5.3 or no openssl available $characters = '0123456789'; $characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/+'; $charactersLength = strlen($characters)-1; $token = ''; //select some random characters for ($i = 0; $i < $length; $i++) $token .= $characters[mt_rand(0, $charactersLength)]; return $token; } /** * var_dump_to_error_log() * Gets the output of the var_dump function and print it out * via the error log. It also removes the end line characters */ function var_dump_to_error_log($parameter) { ob_start(); var_dump($parameter); $ob_get_contents = ob_get_contents(); ob_end_clean(); error_log(str_replace("\n", '', $ob_get_contents)); }