【发布时间】:2020-08-20 10:02:51
【问题描述】:
我无法弄清楚为什么这不起作用。我敢肯定这可能是小事,但我一直在挠头。下面是我的 HTML 和 PHP。
form.html
<form action="result" method="post">
<input type="text" class="form-control" name="hello">
<input type="submit" class="btn btn-primary" value="Submit">
</form>
result.php (.htaccess 设置为允许不使用 .PHP 并且在操作中包含 .PHP 时我收到同样的问题)
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
echo "POST<br>";
}
print_r($_POST);
?>
提交表单会将您发送到 result.php 并显示 POST,但 $_POST 为空。
编辑:.htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ $1 [NE,R=302,L]
提前干杯。
【问题讨论】:
-
action="result.php"而不是action="result"in<form action="result.php" method="post"> -
然后向我们展示您的 .htaccess 实际包含的内容。这听起来像是由于 external 重定向而丢失帖子数据的典型情况,浏览器现在发出 GET 请求。
-
嗨@CBroe 我已经包含了 .htaccess - 为您的帮助欢呼!
-
嘿@Chilarai,我已经尝试过了,不幸的是,它没有任何区别。我认为 CBroe 可能会在正确的轨道上使用 .htaccess