Stack Overflow等网站如何使用action="https://stackoverflow.com/questions/ask/submit"
提交表单?如果使用mod_rewrite,使用POST发送的变量会发送到PHP吗?
我以为mod_rewrite
会失去$_POST
变量?
的.htaccess
的index.php
$q = explode("/", $_SERVER['REQUEST_URI']);
if($q[1]!=""){
switch($q[1]){
case "test":
include("test.php");
break;
...
test.php的
<?php
if(isset($_POST["submitButton"])){
echo "Submitted";
}
else{
echo "Not submitted";
}
?>
<form method="post" action="/test/submit">
<input type="submit" name="submitButton">
</form>
如果我删除action="/test/submit"
如果我的网址是/test
,那么当我点击按钮时,它会返回Not submitted
。
如果我的网址是/test.php
,那么当我点击按钮时,它会返回Submitted
。
更新
暂时,我使用的是以下内容。
的index.php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$q = explode("/", $_POST["url"]);
}
else{
$q = explode("/", $_SERVER['REQUEST_URI']);
}
...
test.php的
<form method="post" action="/">
<input type="hidden" name="url" value="/test">
...
这让我test.php的接收POST变量。
如果有用户没有任何错误,我用header("Location: test/success");
如果有错误,则URL将不得不/
这是不理想的。
更新/解析
问题可能出在Apache 2.4上。此修复程序是该行添加到index.php文件:
parse_str(file_get_contents("php://input"),$_POST);
使用这种方法,没有必要对任何action="..."
(这将成功发布到自身,即使URL是蛞蝓)。
只需尝试一下,找出答案。 – Mike
我有。 'mod_rewrite'失去'$ _POST'变量。 – rybo111
POST变量在内部重定向上继续传递,但不是301s等。但是,如果需要,我相当确信您可以这样做。 –