Edit report at https://bugs.php.net/bug.php?id=64891&edit=1
ID: 64891 User updated by: marc at kryn dot org Reported by: marc at kryn dot org Summary: POST values in Google Chrome XHR. Status: Not a bug Type: Bug Package: Built-in web server Operating System: OS X 10.8.2 PHP Version: 5.4.15 Block user comment: N Private report: N New Comment: Sorry, but you shouldn't modify the test script and then say 'it works with this modification'. I don't know what's the different in the header are to your example, but it's however not important, because mine produces a correct HTTP Request header. Google Chrome sends with my script following header: POST /test3.php?test=1 HTTP/1.1 Host: 127.0.0.1:8000 Connection: keep-alive Content-Length: 7 Cache-Control: max-age=0 Origin: http://127.0.0.1:8000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36 Content-type: application/x-www-form-urlencoded Accept: */* Referer: http://127.0.0.1:8000/test3.php Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 So it's a valid request header and should thus be handled correctly in PHP. You've mentioned a missing Content-Length: it's not missing. You've mentioned a missing charset in the Content-Type: This is not mandatory as you can read in http://tools.ietf.org/html/rfc2616#section-3.7. Please re-open this ticket, since it's still a bug on php's side and not a support question. Previous Comments: ------------------------------------------------------------------------ [2013-05-21 22:15:42] google...@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. This doesn't appear to be a bug in PHP. It looks to me like FireFox and some other UAs will modify the request headers resulting from that javascript code to comply with the spec. Chrome seems to be sending a request, as a result of that javascript XHR, that is missing both the charset in the Content-type header as well as a Content- length header. If I just let the UA do the encoding and formulate the request properly through javascript I get the expected result: <?php if (isset($_GET['test'])) { echo 'received values: <br/>'; var_dump(file_get_contents("php://input"),$_POST,$_GET); exit; } ?> <div id="response"></div> <form id="myform"> <input name="foo" value="bar" type="text" /> </form> <script> var xhr = new XMLHttpRequest(); xhr.open('POST', '<?= $_SERVER['SCRIPT_NAME'] ?>?test=1', true); xhr.onload = function(){ document.getElementById('response').innerHTML = this.responseText; }; var frm = new FormData(document.getElementById("myform")); xhr.send(frm); </script> This works for me in all the latest versions of Chrome, FireFox, Opera, Safari, and IE. Please feel free to reopen this bug report if you have additional evidence of a bug in PHP. ------------------------------------------------------------------------ [2013-05-21 21:24:06] marc at kryn dot org Description: ------------ The PHP file servered through the built-int web server does not receive somehow the POST values from a AJAX/XHR POST call in Google Chrome. Only in Google Chrome. Setup: - Create the file from the test script. - Open a built-in web server `php54 -S 127.0.0.1:8000 -t web/` - Open the file `http://127.0.0.1:8000/test.php` This behaviour happens only for the built-in web server and Google Chrome. It works fine when running PHP behind fpm or as apache module. Any other browser works in all combinations (built-in server or not). Tested on `5.4.15-1` installed through mac ports. Test script: --------------- <?php if (isset($_GET['test'])) { echo 'received values: <br/>'; var_dump($_POST); exit; } ?> <div id="response"></div> <script> var xhr = new XMLHttpRequest(); xhr.open('POST', '<?= $_SERVER['SCRIPT_NAME'] ?>?test=1', true); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.onload = function(){ document.getElementById('response').innerHTML = this.responseText; }; xhr.send('foo=bar'); </script> Expected result: ---------------- received values: array (size=1) 'foo' => string 'bar' (length=3) Actual result: -------------- received values: array (size=0) empty ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=64891&edit=1