zoukankan      html  css  js  c++  java
  • tp5 跨域问题解决

    在config.php 同级的tags.php中的【app_init】添加:

    "app\api\behavior\CORS"  例下图:

    然后在 app/behavior下新建文件:CORS.php,文件路径例下图:

    CORS.php文件内容:

    <?php
    namespace appapiehavior;
    
    use thinkResponse;
    
    class CORS {
    
        public function appInit(){
            if (request()->isOptions()) {
                header('Access-Control-Allow-Origin:*');
                header('Access-Control-Allow-Headers:Accept,Referer,Host,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type,Cookie,token');
                header('Access-Control-Allow-Credentials:true');
                header('Access-Control-Allow-Methods:GET,POST,OPTIONS,PUT,DELETE');
                header('Access-Control-Max-Age:1728000');
                header('Content-Type:text/plain charset=UTF-8');
                header('Content-Length: 0', true);
                header('status: 204');
                header('HTTP/1.0 204 No Content');
            }else{
                header('Access-Control-Allow-Origin:*');
                header('Access-Control-Allow-Headers:Accept,Referer,Host,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type,Cookie,token');
                header('Access-Control-Allow-Credentials:true');
                header('Access-Control-Allow-Methods:GET,POST,OPTIONS');
            }
        }
    
    }

    over!!!

  • 相关阅读:
    php文件包含
    微信劫持反弹shell复现
    DNS劫持
    phpstudy后门漏洞复现
    使用远见远控软件控制靶机
    php基础及工具使用
    nmap扫描
    JavaScript创建对象几种形式
    浅拷贝与深拷贝
    原型和原型链
  • 原文地址:https://www.cnblogs.com/j-jian/p/15007734.html
Copyright © 2011-2022 走看看