コード例 #1
0
ファイル: Csrf.php プロジェクト: arvici/framework
 /**
  * Safely test if token is valid.
  *
  * @param string $name Optional custom name for token.
  * @param string|null $token Don't fetch from POST variable but give the raw token here. (optional).
  *
  * @return bool
  */
 public static function validateToken($name = 'csrfToken', $token = null)
 {
     if ($token === null) {
         $token = Http::getInstance()->request()->paramPost($name);
     }
     if (!is_string($token)) {
         return false;
     }
     return hash_equals($token, Http::getInstance()->session()->get($name));
 }
コード例 #2
0
 public function curlGet($url, $timeout = 5)
 {
     $curl = Http::getInstance();
     $html = $curl->request($url, null, ['timeout' => $timeout]);
     if ($error = $curl->getError()) {
         ++$this->tryTime;
         if ($this->command) {
             $this->command->line("{$url} trying #{$this->tryTime}/{$this->maxTryTimes}# times.");
         }
         if ($this->tryTime > $this->maxTryTimes) {
             if ($this->command) {
                 $this->command->error("[error]{$error}skipped");
                 file_put_contents($this->log, $url . PHP_EOL, FILE_APPEND);
             }
             return false;
         }
         return $this->curlGet($url);
     }
     return $html;
 }