0

How do I retrieve the value of a custom header in PHP sent over AJAX?

I have a cross-domain AJAX request which sends blob data, like so:

var blob = new Blob([req.response], {type: "application/octet-stream"});
req = new XMLHttpRequest();
req.open("POST", ws_path(other_context, 'receive_pkg'), true);
req.setRequestHeader('secret', 'some hedaer value'); //<-- custom header
req.onload = function (oEvent) { alert(req.response); };
req.send(blob);

But in my PHP, when I inspect getallheaders(), I just get (most headers removed for brevity):

...
Access-Control-Request-Method = POST
Access-Control-Request-Headers = content-type,secret
...

My custom header, 'secret', is mentioned in a com-sep list of headers under 'Access-Control-Request-Headers'. But how do I get its actual value?

This question seems to be discussing the same thing, but doesn't cover retrieval.

Community
  • 1
  • 1
Mitya
  • 33,629
  • 9
  • 60
  • 107
  • 1
    does this help? http://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php – SNAG Nov 28 '14 at 14:21
  • I did see that question. I tried the first method proposed in the answer but not the second, more laborious one. I'll give it a go - thanks. – Mitya Nov 28 '14 at 16:32

0 Answers0