Piwik\Common::getRandomString PHP Méthode

getRandomString() public static méthode

Do not use for security related purposes (the string is not truly random).
public static getRandomString ( integer $length = 16, string $alphabet = "abcdefghijklmnoprstuvwxyz0123456789" ) : string
$length integer string length
$alphabet string characters allowed in random string
Résultat string random string with given length
    public static function getRandomString($length = 16, $alphabet = "abcdefghijklmnoprstuvwxyz0123456789")
    {
        $chars = $alphabet;
        $str = '';
        for ($i = 0; $i < $length; $i++) {
            $rand_key = mt_rand(0, strlen($chars) - 1);
            $str .= substr($chars, $rand_key, 1);
        }
        return str_shuffle($str);
    }

Usage Example

 protected function write(array $record)
 {
     switch ($record['level']) {
         case Logger::EMERGENCY:
         case Logger::ALERT:
         case Logger::CRITICAL:
         case Logger::ERROR:
             $context = Notification::CONTEXT_ERROR;
             break;
         case Logger::WARNING:
             $context = Notification::CONTEXT_WARNING;
             break;
         default:
             $context = Notification::CONTEXT_INFO;
             break;
     }
     $message = $record['level_name'] . ': ' . htmlentities($record['message']);
     $notification = new Notification($message);
     $notification->context = $context;
     $notification->flags = 0;
     try {
         Manager::notify(Common::getRandomString(), $notification);
     } catch (Zend_Session_Exception $e) {
         // Can happen if this handler is enabled in CLI
         // Silently ignore the error.
     }
 }
All Usage Examples Of Piwik\Common::getRandomString