本文整理汇总了PHP中Api::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Api::validate方法的具体用法?PHP Api::validate怎么用?PHP Api::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Api
的用法示例。
在下文中一共展示了Api::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exit
break;
case EX_NOPERM:
Http::response(403, $code, 'text/plain');
break;
case EX_DATAERR:
case EX_NOINPUT:
default:
Http::response(416, $code, 'text/plain');
}
}
exit($code);
}
//Remote hosts need authorization.
if ($remotehost) {
$ip = $_SERVER['REMOTE_ADDR'];
$key = $_SERVER['HTTP_USER_AGENT'];
//pulling all tricks.
//Upto 10 consecutive errors allowed...before a 5 minute timeout.
//One more error during timeout and timeout starts a new clock
if ($_SESSION['api']['errors'] > 10 && time() - $_SESSION['api']['time'] <= 5 * 60) {
// timeout!
api_exit(EX_NOPERM, "Remote host [{$ip}] in timeout - error #" . $_SESSION['api']['errors']);
}
//Check API key & ip
if (!Validator::is_ip($ip) || !Api::validate($key, $ip)) {
api_exit(EX_NOPERM, 'Unknown remote host [' . $ip . '] or invalid API key [' . $key . ']');
}
//At this point we know the remote host/IP is allowed.
$_SESSION['api']['errors'] = 0;
//clear errors for the session.
}
示例2: requireApiKey
function requireApiKey()
{
# Validate the API key -- required to be sent via the X-API-Key
# header
if (!isset($_SERVER['HTTP_X_API_KEY'])) {
Http::response(403, "API key required");
} else {
if (!Api::validate($_SERVER['HTTP_X_API_KEY'], $_SERVER['REMOTE_ADDR'])) {
Http::response(401, "API key not found or source IP not authorized");
}
}
}