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等。但是,如果需要,我相當確信您可以這樣做。 –