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