Incorrect HttpRequest->isXMLHttpRequest value in apache 2.4 #6010
Comments
@pobidowski is there any replacement for it? |
@Ocramius Yes, php function "apache_request_headers();" contains value of this header under key "X_REQUESTED_HTTP" |
if ($this->getRequest()->isXmlHttpRequest()) {
// do stuff
} To make sure this is not because of |
Sorry, I mean "X_REQUESTED_WITH". I have Apache 2.4.6 (only mod_rewrite enabled) and it does not work properly. |
I did some testing with Apache 2.4.9 and think this info can be useful. The feature that is mentioned in the topic on Stack Overflow is about custom headers and does not seem to affect $_SERVER variable
apache_request_headers()
Test script: <?php
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and 'XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) {
var_dump($_SERVER);
echo '<hr />';
var_dump(apache_request_headers());
exit;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Apache ENV test</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
//<![CDATA[
$(function () {
$('button').click(function () {
$.ajax({
type : 'GET',
url : '<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?>',
beforeSend: function (xhr) {
xhr.setRequestHeader('CUSTOM-HEADER-WITH-DASHES', 'Value for header with dashes');
xhr.setRequestHeader('CUSTOM_HEADER_WITH_UNDERSCORES', 'Value for header with underscores');
},
success : function(data) {
$('#ajax-result').html(data);
}
});
});
});
//]]>
</script>
</head>
<body>
<button>Click me!</button>
<hr />
<div id="ajax-result"></div>
</body>
</html> |
Thanks for Your explanation. It seems that I send this header with wrong name (uppercase with underscore version). It works fine until I have tested it on Apache 2.4.6. |
This issue has been closed as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html |
According to http://stackoverflow.com/questions/18185366/header-names-with-underscores-ignored-in-php-5-5-1-apache-2-4-6 header "X_REQUESTED_HTTP" in Apache 2.4 is not available in $_SERVER variable. Therefore, the isXMLHttpRequest method from \Zend\Http\Request returns false which is incorrect value.
The text was updated successfully, but these errors were encountered: