1

I am trying to find a way to check the headers that have already been set by PHP. Example:

<?php
header('Location: https://www.google.fr');

// Later in the code
$location = get_header('Location');

Obviously, the get_header function does not exist and I can't find a way to access already set headers.

Is that even possible?

EDIT after comments:

headers_sent is not the function I am looking for. This functions checks if the headers have already been sent to the client.

Blackbam
  • 17,496
  • 26
  • 97
  • 150
Hammerbot
  • 15,696
  • 9
  • 61
  • 103
  • [getallheaders()](http://php.net/manual/en/function.getallheaders.php) ? – CD001 Apr 03 '18 at 15:54
  • 2
    http://php.net/manual/en/function.headers-sent.php - first Google result btw. for your question title verbatim ... – CBroe Apr 03 '18 at 15:55
  • @CD001 `getallheaders` gets request headers I think, and @CBroe I think that the `headers_sent` function is a boolean that says if the headers have already been sent to the client – Hammerbot Apr 03 '18 at 15:56
  • I don't want to check if the headers have already been sent, I want to check the value of a pending header to be sent.. – Hammerbot Apr 03 '18 at 15:58
  • ... but if it's a pending header to be send, how do you expect to check it if it's not been sent yet? – CD001 Apr 03 '18 at 15:59
  • I don't want to check if it has been sent, I want to check the value that has been assigned to this header – Hammerbot Apr 03 '18 at 15:59
  • 3
    What about http://php.net/manual/en/function.headers-list.php – Alon Eitan Apr 03 '18 at 16:01
  • 1
    That seems better @AlonEitan, thank you, you can make it a response, I will mark it as resolved – Hammerbot Apr 03 '18 at 16:01
  • I voted to reopen, since it's obviously not a duplicate – Alon Eitan Apr 03 '18 at 16:03
  • 1
    @AlonEitan ... at least not a duplicate of *that* question, I bet if someone was to rummage enough it'll be here, somewhere ;) Good catch on the OP wanting the **response** headers. – CD001 Apr 03 '18 at 16:04
  • Thank you, I see the obviousness of the question here, but I could not find any result in google, maybe I should have had to browse on the PHP doc directly – Hammerbot Apr 03 '18 at 16:04
  • There is probably a different duplicate - If you wish you can delete this question and then we can pretend like this never happened ;) – Alon Eitan Apr 03 '18 at 16:07
  • To be honest, there are questions about the `headers_list` function, that are relative to the behaviour of the function in itself, see https://stackoverflow.com/questions/31555392/php-headers-list-is-not-showing-all-headers https://stackoverflow.com/questions/17646229/get-php-content-type-from-header or https://stackoverflow.com/questions/4475345/unsorted-array-headers-list-make-keys-for-array but none of them respond to the exact same question. Anyways, the community will decide to reopen or not. But I think @AlonEitan deserves his 25 points for that as he responded to the question. – Hammerbot Apr 03 '18 at 16:12
  • That's totally fine by me @Hammerbot, I'm not doing this for the reputation :) – Alon Eitan Apr 03 '18 at 16:12
  • headers_sent() method in php you can use – Sachin Aghera Apr 03 '18 at 16:20

0 Answers0