php apache uses cors to achieve cross-domain

巴扎黑
Release: 2016-11-08 11:56:31
Original
2258 people have browsed it

apaceh configuration:

 ServerAdmin xxx@qq.com DocumentRoot "C:/htdocs/demo" ServerName dev.dd.cn ##ErrorLog "logs/dummy-host.localhost-error.log" ##CustomLog "logs/dummy-host.localhost-access.log" combined  #Require all denied Header set Access-Control-Allow-Origin *  
Copy after login

PHP file settings:

Copy after login

The meaning of the configuration is to allow requests initiated by any domain to obtain the data of the current server. Of course, this is very dangerous, and malicious sites may attack our servers through XSS. Therefore, we should try our best to limit security sources in a targeted manner. For example, the following settings allow only the domain http://feng.com to access the server's API across domains.

httpd.conf:

 ServerAdmin xxx@qq.com DocumentRoot "C:/htdocs/demo" ServerName dev.dd.cn ##ErrorLog "logs/dummy-host.localhost-error.log" ##CustomLog "logs/dummy-host.localhost-access.log" combined  #Require all denied Header set Access-Control-Allow-Origin http://feng.com  
Copy after login

PHP file:

header("Access-Control-Allow-Origin:http://feng.com");
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!