本文整理汇总了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;
}