Browse Source

跨域问题

wufeng 2 years ago
parent
commit
4fd0ee97dc
1 changed files with 9 additions and 0 deletions
  1. 9 0
      public/index.php

+ 9 - 0
public/index.php

@@ -14,6 +14,15 @@ namespace think;
 
 require __DIR__ . '/../vendor/autoload.php';
 
+header('Access-Control-Allow-Origin:*');
+header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE');
+header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
+// 执行HTTP应用并响应
+if($_SERVER['REQUEST_METHOD']=="OPTIONS"){
+    echo '';
+    exit();
+}
+
 // 执行HTTP应用并响应
 $http = (new App())->http;