本文整理匯總了PHP中Http::getInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Http::getInstance方法的具體用法?PHP Http::getInstance怎麽用?PHP Http::getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Http
的用法示例。
在下文中一共展示了Http::getInstance方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validateToken
/**
* 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: curlGet
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;
}