nginx - website cross-domain issues
PHP中文网
PHP中文网 2017-05-16 17:11:39
0
5
475

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中文网

认证高级PHP讲师

reply all(5)
伊谢尔伦

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');  
某草草

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.

为情所困

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

阿神

Remember not to produce any output before the header is executed

为情所困

Apache (.htaccess):

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

Nginx:

add_header Access-Control-Allow-Origin *;

PHP:

header('Access-Control-Allow-Origin:*');
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template