search

Home  >  Q&A  >  body text

nginx - website cross-domain issues

Cross-domain problem, my website can already be accessed, but it needs to be cross-domain. Baidu only told me that the origin site is set to: Access-Control-Allow-Origin: *
I was very confused and searched online, and the simplest solution given was to add the above code, but I didn’t Do you know which php file to add to it? There are many php files under the wordpress file. Also, I am using a virtual host or other server files.

The files under webroot are too I really hope someone can help me and make it as simple as possible. I am basically a novice when it comes to coding, and I still don’t understand some basic tags of HTML

Anyway, how to add cross-domain code to which file

PHP中文网PHP中文网2780 days ago476

reply all(5)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-16 17:13:39

    Ignore those boring people who step on you. Didn’t you clearly say that you are a novice? Set up a cross-domain header on a public php page (such as a configuration page)

        // 指定允许其他域名访问,*为任意.  
        header('Access-Control-Allow-Origin:*');  
        // 响应类型,方便ajax等跨  
        header('Access-Control-Allow-Methods:POST');  
        // 响应头设置  
        header('Access-Control-Allow-Headers:x-requested-with,content-type');  

    reply
    0
  • 某草草

    某草草2017-05-16 17:13:39

    Add a line to index.php in the root directory of the website:

    header('Access-Control-Allow-Origin:*');//设置允许跨域
    
    

    People nowadays are so incompetent and their own level is not that good. They also like to give negative marks to others and express their condolences to the original poster.

    reply
    0
  • 为情所困

    为情所困2017-05-16 17:13:39

    You don’t even understand html, I suggest you learn the basics first.
    Search on Baidu and set the header in php

    reply
    0
  • 阿神

    阿神2017-05-16 17:13:39

    Remember not to produce any output before the header is executed

    reply
    0
  • 为情所困

    为情所困2017-05-16 17:13:39

    Apache (.htaccess):

    Header set Access-Control-Allow-Origin "*"
    

    Nginx:

    add_header Access-Control-Allow-Origin *;
    

    PHP:

    header('Access-Control-Allow-Origin:*');
    

    reply
    0
  • Cancelreply