'Empty PHP POST Variables
Background
Web-based contact form.
Problem
The $_POST
array is empty. When errors are enabled, no errors (except empty array values) are found. The code was tested and working at one point, then left untouched until I posted this question. The host might have performed an upgrade.
Software
- PHP 5.2.17
- Apache 2.0.63
- SSI
HTML Form
The HTML form is as follows:
<form method="post" action="contact.php" id="commentForm">
<label for="name">Name</label>
<input type="text" name="name" id="name" maxlength="64" /><br />
<label for="email">Email</label>
<input type="text" name="email" id="email" maxlength="320" /><br />
<label for="message">Message</label>
<textarea name="message" rows="10" cols="40" id="Message"></textarea><br />
<label for="human">40 + 2 =</label>
<input type="text" name="human" id="human" size="10" maxlength="3" /><br />
<p align="center">
<input type="submit" name="submit" value="Send" class="submit-button" />
</p>
</form>
PHP Code
The following code is called when the form is submitted:
$reason = 'default';
error_reporting( 0 );
ini_set( 'display_errors', 0 );
ini_set( 'register_globals', 0 );
ini_set( 'allow_url_fopen', 0 );
ini_set( 'expose_php', 0 );
ini_set( 'magic_quotes_gpc', 0 );
function not_contacted() {
global $reason;
// Redirects to computer, name, email, or message.
//
header( 'Location: ../error-'.$reason.'.shtml' );
}
function wms_error_handler($errno, $errstr, $errfile, $errline) {
not_contacted();
return true;
}
function wms_shutdown() {
if( is_null( $e = error_get_last() ) === false ) {
not_contacted();
}
}
set_error_handler( "wms_error_handler" );
register_shutdown_function( 'wms_shutdown' );
$name = trim( stripslashes( $_POST["name"] ) );
Logging
echo $_SERVER["REQUEST_METHOD"];
== GET
print_r( $_GET );
== Array ( )
print_r( $_POST );
== Array ( )
print_r( $_REQUEST );
==
Array ( [__utma] => 181723617.1357984856.1311884601.1313715852.1313720411.12 [__utmz] => 181723617.1313720411.12.10.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=jigo [__utmc] => 181723617 [__utmb] => 181723617.3.10.1313720411 ) `
file_get_contents('php://input')
== Empty
Questions
- What could be causing the PHP POST variable values to be empty?
- Why is the
POST
method being transmogrified into aGET
method?
I think it is a php.ini or httpd.conf conflict, but cannot be sure (it is a hosted domain).
Thank you.
Update
The following test works.
test.shtml
<html>
<body>
<form method="post" action="test.php">
<input type="hidden" name="test" value="test" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
test.php
<?
echo $_POST["test"];
?>
Solution
Removed the following line from the .htaccess
file:
RewriteRule ^(.*)$ http://www.whitemagicsoftware.com/$1 [R=301,L]
Solution 1:[1]
I also had a similar issue.
The problem was the data were posted to the http url, but there was a redirection to the https version of the url. Datas in $_POST are lost during the redirect.
I hope this can help others
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mohand |