本文整理汇总了PHP中is_allowed_http_origin函数的典型用法代码示例。如果您正苦于以下问题:PHP is_allowed_http_origin函数的具体用法?PHP is_allowed_http_origin怎么用?PHP is_allowed_http_origin使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_allowed_http_origin函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send_origin_headers
/**
* Send Access-Control-Allow-Origin and related headers if the current request
* is from an allowed origin.
*
* If the request is an OPTIONS request, the script exits with either access
* control headers sent, or a 403 response if the origin is not allowed. For
* other request methods, you will receive a return value.
*
* @since 3.4.0
*
* @return bool|string Returns the origin URL if headers are sent. Returns false
* if headers are not sent.
*/
function send_origin_headers()
{
$origin = get_http_origin();
if (is_allowed_http_origin($origin)) {
@header('Access-Control-Allow-Origin: ' . $origin);
@header('Access-Control-Allow-Credentials: true');
if ('OPTIONS' === $_SERVER['REQUEST_METHOD']) {
exit;
}
return $origin;
}
if ('OPTIONS' === $_SERVER['REQUEST_METHOD']) {
status_header(403);
exit;
}
return false;
}
示例2: send_origin_headers
/**
* Send Access-Control-Allow-Origin and related headers if the current request
* is from an allowed origin.
*
* @since 3.4.0
*
* @return bool|string Returns the origin URL if headers are sent. Returns false
* if headers are not sent.
*/
function send_origin_headers()
{
$origin = get_http_origin();
if (!is_allowed_http_origin($origin)) {
return false;
}
@header('Access-Control-Allow-Origin: ' . $origin);
@header('Access-Control-Allow-Credentials: true');
return $origin;
}