PHPDaemon\Core\Daemon::uniqid PHP Method

uniqid() public static method

Generate a unique ID.
public static uniqid ( ) : string
return string Returns the unique identifier, as a string.
    public static function uniqid()
    {
        static $n = 0;
        return str_shuffle(md5(str_shuffle(microtime(true) . chr(mt_rand(0, 0xff)) . Daemon::$process->getPid() . chr(mt_rand(0, 0xff)) . ++$n . mt_rand(0, mt_getrandmax()))));
    }

Usage Example

Exemplo n.º 1
0
 public function perform()
 {
     $hash = Request::getString($_REQUEST['x']);
     if (!strlen($hash) || base64_decode($hash, true) === false) {
         $this->req->setResult(['success' => false, 'error' => 'Wrong format of extTokenHash']);
         return;
     }
     $this->appInstance->externalAuthTokens->findByExtTokenHash($hash, function ($result) use($hash) {
         if ($result) {
             $this->req->setResult(['success' => false, 'error' => 'This token was already used.']);
             return;
         }
         $ip = $this->req->getIp();
         $intToken = Crypt::hash(Daemon::uniqid() . "" . $ip . "" . Crypt::randomString());
         $this->appInstance->externalAuthTokens->save(['extTokenHash' => $hash, 'intToken' => $intToken, 'ip' => $ip, 'useragent' => Request::getString($_SERVER['HTTP_USER_AGENT']), 'ctime' => microtime(true), 'status' => 'new'], function ($lastError) use($intToken) {
             if (!isset($lastError['n']) || $lastError['n'] === 0) {
                 $this->req->setResult(['success' => false, 'errors' => ['code' => 'Sorry, internal error.']]);
                 return;
             }
             $type = Request::getString($_REQUEST['type']);
             if ($type === 'email') {
                 // send email....
             } elseif ($type === 'redirect') {
                 $this->req->redirectTo(HTTPClient::buildUrl(['/' . $this->req->locale . '/account/extauth', 'i' => $intToken]), false);
             }
             $this->req->setResult(['success' => true, 'intToken' => $intToken]);
         });
     });
 }
All Usage Examples Of PHPDaemon\Core\Daemon::uniqid