php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31417 $HTTP_RAW_POST_DATA but $_POST not populated
Submitted: 2005-01-05 15:55 UTC Modified: 2009-11-20 17:07 UTC
Votes:37
Avg. Score:4.2 ± 1.1
Reproduced:32 of 34 (94.1%)
Same Version:11 (34.4%)
Same OS:14 (43.8%)
From: j-spam at starline dot ee Assigned:
Status: No Feedback Package: CGI/CLI related
PHP Version: 5.0.3 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: j-spam at starline dot ee
New email:
PHP Version: OS:

 

 [2005-01-05 15:55 UTC] j-spam at starline dot ee
Description:
------------
$_POST is not populated, however $HTTP_RAW_POST_DATA is.

lighttpd 1.3.5 using cgi (not fcgi)
CGI-PHP5 5.0.3
Firefox 1.0

Reproduce code:
---------------
$_POST: <?php print_r($_POST); ?><br>
$HTTP_RAW_POST_DATA: <?php print_r($_HTTP_RAW_POST_DATA); ?><br><br>
<form action="<?=$_SERVER["PHP_SELF"] ?>" method="post">
	<textarea name="duh"><?=$_POST["duh"];?></textarea>
	<input type="submit" />
</form>

Actual result:
--------------
$_POST: Array ( )
$HTTP_RAW_POST_DATA: bla=asdf&duh=eeca%0D%0Aasdf%0D%0Aasdf

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-05 15:58 UTC] j-spam at starline dot ee
Typo: "$HTTP_RAW_POST_DATA" not "$_HTTP_RAW_POST_DATA" on Reproduce code, line 2.
 [2005-01-05 16:03 UTC] j-spam at starline dot ee
btw $_GET works.
 [2005-02-28 21:07 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-03-01 18:18 UTC] csaba at alum dot mit dot edu
Huge problem.  This just started happening on my Win XP Pro (SP 2) machine - checked with both the Feb 28 snapshots and March 1 snapshots.  It was not happening on the Feb 19 snapshots, but I think it might be going on since Feb 25 because of: http://bugs.php.net/bug.php?id=32109
I am using Apache 2.0.53 and I have php.ini in c:\windows.
Besides that I have the following 4 files in c:\winapps\php.net\latest: php.exe, php-win.exe, php5ts.dll, and php5apache2.dll, a fairly minimalistic setup.

Csaba Gabor from Vienna
 [2005-03-08 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-07-18 07:03 UTC] robbhammack at gmail dot com
I'm also having this issue. $_GET and $HTTP_RAW_POST_DATA are populated, but $_REQUEST and $_POST are not.
I'm trying to develop an application for php5 but whithout being able to post form data, I'm going to have to go back to php4 which would be a real shame.

OS is win2K xp2
PHP Version 5.1.0b3
System 	Windows NT MINERVA 5.1 build 2600
Build Date 	Jul 14 2005 20:32:24
Configure Command 	cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared"
Server API 	Apache 2.0 Handler
Virtual Directory Support 	enabled
Configuration File (php.ini) Path 	C:/Development/programs/php5/php.ini
PHP API 	20041225
PHP Extension 	20050617
Zend Extension 	220050617

Apache Version 	Apache/2.0.53 (Win32) PHP/5.1.0b3 DAV/2
Apache API Version 	20020903
Loaded Modules 	core mod_win32 mpm_winnt http_core mod_so mod_access mod_actions mod_alias mod_asis mod_auth mod_autoindex mod_cgi mod_dav mod_dav_fs mod_dir mod_env mod_imap mod_include mod_info mod_isapi mod_log_config mod_mime mod_negotiation mod_setenvif mod_userdir mod_php5
 [2006-05-15 14:53 UTC] baker195 at btinternet dot com
I'm writing an AJAX application and after using the XLMHttpRequest object to post the data to my server side PHP script, I have to extract the data from $HTTP_RAW_POST_DATA as $_POST is empty.
 [2006-05-16 15:23 UTC] fabiovh at nospammers dot gmail dot com
//workaround

if (isset($GLOBALS['HTTP_RAW_POST_DATA']) && !count($_POST))
  parse_str($GLOBALS['HTTP_RAW_POST_DATA']  , $_POST);
 [2008-05-22 18:57 UTC] mgb at matthewbelden dot com
This workaround did it for me, the above did not.

$pattern = "/\n/";
$replace = "&";
$GLOBALS['HTTP_RAW_POST_DATA'] = preg_replace($pattern, $replace, $GLOBALS['HTTP_RAW_POST_DATA']);
if (isset($GLOBALS['HTTP_RAW_POST_DATA']) && !count($_POST))
  parse_str($GLOBALS['HTTP_RAW_POST_DATA']  , $_POST);
 [2008-05-22 20:46 UTC] mgb at matthewbelden dot com
sorry in the previous comment the pattern should be \r\n not just \n
 [2009-11-20 16:34 UTC] daniel dot kirsch at birgin dot de
I run into the same problem with my ajax application.

When using a XMLHTTPRequest instance I need to provide the data in the following way:

key=value&anotherkey=anothervalue

So each key/value pair is separated by "&". Additionally I need to define the correct request header which must be set after opening the connection and before sending the request:

var postData = "key=value&anotherkey=anothervalue";
var ajax = new XMLHttpRequest();
ajax.open("POST",url,false);
ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
ajax.send(postData);

When doing it this way I receive the correct values in $_POST. $HTTP_RAW_POST_DATA is empty. When not defining the request header $HTTP_RAW_POST_DATA contains the data and $_POST is empty.
 [2009-11-20 17:07 UTC] rasmus@php.net
Daniel, that's the way it is supposed to work.  By default $HTTP_RAW_POST_DATA is not populated if we see a known encoding.  With a known encoding we decode it and populate $_POST.  If you want to force $HTTP_RAW_POST_DATA to always be populated turn on always_populate_raw_post_data in your .ini
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 12:01:29 2024 UTC