1

How can I add a Http header to all of my pages? The website I'm working was developed using CakePhP and I would like to add the header below to all pages.

Access-Control-Allow-Origin: https://url_of_my_website

Thanks in advance for any help!

1 Answer 1

3

You can use this:

In AppController.php
public function beforeRender()
{
    $this->response->header('Access-Control-Allow-Origin', 'your url');
}
Sign up to request clarification or add additional context in comments.

1 Comment

In CakePHP 4 this is now $this->response = $this->response->withHeader('X-CakePHP', 'yes!');, because the response object is immutable therefore must be replaced.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.