Where in pkhp file to place this command?

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

it is necessary to address to pkhp through $ .post

  • Before the first echo or other output, usually at the beginning of the script - Naumov
  • Do you want to send a post request to your php script? - korytoff
  • The script is on my server and this is my script - Mykola Kіkets

1 answer 1

Before the first content output. And where it depends on your architecture, framework, etc.

You can also use the check:

 if (!headers_sent()) { header('Access-Control-Allow-Origin: *'); } else { // обработка ошибки или уведомление разработчикам } 
  • when I install it, it sees a local error Uncaught SyntaxError: Unexpected token < index.html:2 - Mykola Kіckiez
  • @ МиколаКікець I do not suffer from telepathy unfortunately ... What? - korytoff
  • Uncaught SyntaxError: Unexpected token < index.html:2 - Mykola Kіkets
  • @MykolaKіkets well, this is php code that needs to be inserted into php scripts. Are you familiar with PHP ? - korytoff
  • Server page code: - Mikola Kіkets