Puya Sarmidani Puya Sarmidani - 5 months ago 20
Ajax Question

Custom headers not showing with $_SERVER

Im trying to set a custom header like the code below:

$.ajax({
type:"POST",
beforeSend: function (request)
{
request.setRequestHeader("X_PJAX", 'true');
},
url: url,
dataType: 'json',
success: function(msg) {
console.log(msg);
}
});


The response is a 200 OK so i assume that it went ok.
But when i try getting the headers with
print_r($_SERVER)
it shows all the headers except the custom one i just set.

Has this something to do with Apache or with my code?

I've checked mod_headers and it is enabled.
Also tried to set the custom header with PHP and still no result and no errors.

Answer

You should use apache_request_headers read more about this here APACHE REQUEST HEADERS $_SERVER contains Predefined values for the system and server , apache_request_headers will get your custom added headers.:

print_r(apache_request_headers());
Comments