W
W
WebDev2019-10-14 10:17:04
PHP
WebDev, 2019-10-14 10:17:04

Why doesn't CORS work in php?

Please help me figure it out, I'm at an impasse.
Created a file /var/www/test/index.php.
Added it to nginx so that it can be accessed by test.local .
Created an index.html file that accesses test.local via AJAX.
I get an error that you can not contact a third-party domain.
Okay, really not, because there are no headers.
I put headers in index.php:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization, Access-Control-Allow-Methods, Access-Control-Request-Headers');

echo 'test';

The same. And if everywhere the asterisks put down the same thing and how I just did not try. And the headers are visible in chrome dev tools.
If these headers are written in the nginx config, then it works.
What's wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question