php - PHP Post Empty 根据请求
问题描述
我无法弄清楚为什么这不起作用。我敢肯定这可能是小事,但我一直在挠头。下面是我的 HTML 和 PHP。
表单.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]
提前喝彩。
解决方案
在@mickmackusa 和@CBroe 的帮助下,确定问题出在.htaccess
文件上。
删除 .PHP 扩展名时,它是重定向而不是重写。解决方案是将其更改.htaccess
为以下内容:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
感谢大家的帮助。
推荐阅读
- error-handling - 修改后的 Rust Book 猜谜游戏查询
- windows - 在 Win 控制台上创建原始 git 树
- apache - 使用 SSL 为子域设置 .access
- point-cloud-library - 带有 pcl 的 IterativeClosestPoint 没有给出预期的结果
- r - 每个过滤后的数据集具有不同颜色的散点图
- html - 作为电子邮件模板发送时,图像路径被打乱
- c# - 如何在 C# 中获取数字角色 OnEnroll 事件
- html - 背景图片没有填满整个页面
- swift - 如何在 SwiftUI 中从一个视图重定向到另一个视图?
- node.js - 如何从反应提交多部分/表单数据到表达?