php HTTP_ORIGIN未设置

时间:2015-06-08 08:11:11

标签: php cors

我正在尝试使用以下代码使用php实现CORS

//will add domains in this array
$allowedOrigins = array();

if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] != '') {
  foreach ($allowedOrigins as $allowedOrigin) {
    if (preg_match('#' . $allowedOrigin . '#', $_SERVER['HTTP_ORIGIN'])) {
      header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
      header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
      header('Access-Control-Max-Age: 86400');
      header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
      break;
    }
  }
}

$ _ SERVER [' HTTP_ORIGIN']不返回任何内容(空字符串) HTTP_ORIGIN还有其他选择吗? 或者我做错了什么?

0 个答案:

没有答案