# Header in Response

**URL:** https://discourse.slimframework.com/t/header-in-response/5037
**Category:** Questions
**Created:** [December 9, 2021, 7:37pm UTC](https://discourse.slimframework.com/t/header-in-response/5037 "2021-12-09T19:37:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ogurchik](https://avatars.discourse-cdn.com/v4/letter/o/c57346/32.png) [@ogurchik](https://discourse.slimframework.com/u/ogurchik)
#### Post date: [December 9, 2021, 7:37pm UTC](https://discourse.slimframework.com/t/header-in-response/5037/1 "2021-12-09T19:37:00Z")

</div>

I’m reading doc of Slin4 and I trying do this -  
$response = new Response();  
$response-\>withHeader(‘Location’, ‘[https://www.example.com](https://www.example.com)’);  
print\_r($response-\>getHeaders());  
But it print nothing. I try googling and i didn’t understand what is wrong

---

<div class="post-metadata">

### Author: ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)
#### Post date: [December 10, 2021, 9:21am UTC](https://discourse.slimframework.com/t/header-in-response/5037/2 "2021-12-10T09:21:57Z")

</div>

> [@ogurchik](#):
>
> $response-\>withHeader(‘Location’, ‘[https://www.example.com](https://www.example.com)’);

The PSR-7 request and response headers are “immutable”. So try this:

```auto
$response = $response->withHeader('Location', 'https://www.example.com');

```

---

<div class="post-metadata">

### Author: ![ogurchik](https://avatars.discourse-cdn.com/v4/letter/o/c57346/32.png) [@ogurchik](https://discourse.slimframework.com/u/ogurchik)
#### Post date: [December 10, 2021, 7:14pm UTC](https://discourse.slimframework.com/t/header-in-response/5037/3 "2021-12-10T19:14:23Z")

</div>

> [@odan](#):
>
> ```auto
> $response = $response->withHeader('Location', 'https://www.example.com');
> 
> ```

Hmmm, it is working! Thank you. I’m in deep shock. This method gives back the whole object of response?

---

<div class="post-metadata">

### Author: ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)
#### Post date: [December 10, 2021, 8:40pm UTC](https://discourse.slimframework.com/t/header-in-response/5037/4 "2021-12-10T20:40:19Z")

</div>

Yes, it creates a “clone”, changes or adds the new value and returns the cloned object.
