I am passing header by ajax,
$.ajax({
headers: {
key: value
}
});
I can see the value in Request Header
in the browser. I am using Codeigniter to get key by $this->input->get_request_header('key')
.
It is working fine in local but not working on the server.
I have tried apache_request_headers()
and $_SERVER
and getallheaders()
and etc.. but i cannot see my custom header in this array.
So how to get this custom header by PHP?
2
Answers
This is an example of how to set a header in an Ajax request.
By sending it that way you don’t have to have problems receiving it in your backend with Codeigniter 3.1.11 which is the one that includes the function you are using.
I had this issue with Codeigniter 3 and
Authorization
header. It was working locally but didn’t work on the server. I found out that other headers work – I’ve changedAuthorization
toAuthorization2
just to test. The PHPgetallheaders()
method was also returning all headers with theAuthorization
header filtered out.This led me to this answer so I’ve added:
to the
.htaccess
file and theAuthorization
header reappeared.