Addressing POST Request Malfunction in PHP
In the presented code snippet:
<pre><?php echo $_POST['ss'];?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input name="ss" type="text" />
<input type="submit" name="submit">
</form>
</pre>
The intention is to capture the input from the text box and display it when the submit button is clicked. However, the output remains blank. While the method="get" works seamlessly, method="post" poses a problem.
Troubleshooting the POST Request
To resolve this issue, consider the following steps:
Check the Action Attribute:
If you are refreshing the page, set the action attribute to an empty string, e.g.:
action=''
instead of:
action="<?php echo $_SERVER['PHP_SELF'];?>"
Configure POST Data Handling:
Add the following line at the beginning of your PHP file to handle POST data properly:
if(empty($_SERVER['CONTENT_TYPE']))
{
$_SERVER['CONTENT_TYPE'] = "application/x-www-form-urlencoded";
}
Review php.ini Settings:
Ensure that the following settings exist in your php.ini file:
post_max_size = 8M
variables_order = "EGPCS"
Restart Apache (if necessary):
If you modify php.ini and PHP runs as an Apache module, restart Apache using a command like:
sudo /etc/init.d/httpd restart
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3