In my case, when posting from HTTP to HTTPS, the $_POST comes empty. The problem was, that the form had an action like this //example.com When I fixed the URL to https://example.com , the problem disappeared. I think is something related on how the server is setup. I am having the same issues using GoDaddy as a host.
PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables. The example below shows a form with an input field and a submit button.
The PHP built-in variable $_POST is also an array and it holds the data that we provide along with the post method.
$_POST is a predefined variable which is an associative array of key-value pairs passed to a URL by HTTP POST method that uses URLEncoded or multipart/form-data content-type in request. $HTTP_POST_VARS also contains the same information, but is not a superglobal, and now been deprecated.
When using JSON content-type the $_POST
array will not populate (only with multi-part forms I believe)
Here is how I correct the issue:
$_POST = json_decode(file_get_contents("php://input"), true);
Here's another possible cause -- my form was submitting to domain.com without the WWW. and I had set up an automatic redirect to add the "WWW." The $_POST array was getting emptied in the process. So to fix it all I had to do was submit to www.domain.com
I had a similar problem. Turned out to be a simple fix. In the form I had
<form action="directory" method="post">
where directory was the name of... the directory. My POST array was totally empty. When I looked at the url in my browser, it was displayed with a forward slash on the end.
Adding the forward slash to the end of my action did the trick -
<form action="directory/" method="post">
My $_POST array was full again!
Make sure that, in php.ini:
track_vars
(it's only available on very old PHP versions) is set to On
variables_order
contains the letter P
post_max_size
is set to a reasonable value (e.g. 8 MB)suhosin.post.max_vars
and suhosin.request.max_vars
are large enough.I suppose the second suggestion of mine will solve your problem.
I've found that when posting from HTTP to HTTPS, the $_POST
comes empty.
This happened while testing the form, but took me a while until I realize that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With