PHP: Fix For The Empty $_POST Array

One of the reasons I “love” PHP so much is that it sometimes poses problems the solution of which makes you scratch your head in wonder. Take for example the spurious “empty $_POST array” problem. It is easy to recognize for what happens is that parameters passed to a PHP script via a POST request won’t show up in the $_POST superglobal array.
To fix this, first make sure that you really pass the parameters. This can be easily checked:

{openx:6}

<?php
  $mypostdata = file("php://input");
  print "<pre>"; 
  var_dump($_POST);
  var_dump($mypostdata);
  print "</pre>"
?>

If your installation of PHP is ok, you should see the POST data you send to this script in both dumped outputs. If you see the data only in the second dump ($mypostdata), chances are your PHP installation is broken.

To fix it, all you need to do is reconfigure PHP with the additional flag

--enable-safe-mode

and compile the whole thing. Don’t worry, though! You don’t have to actually use “safe mode” afterwards. You just need to compile PHP with that setting. If you so wish you can disable safe mode afterwards by putting

safe_mode = Off

in your

php.ini

. Makes me really scratch my head in wonder about the internal code dependencies ;)

Incoming search terms:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>