簡體   English   中英

提交表單時,顯示-該網頁具有重定向循環

[英]On form submit, it says - This webpage has a redirect loop

這是我第一次在此代碼中苦苦掙扎后尋求幫助。 我已經嘗試了所有可能的方法,但是似乎無法使其正常工作。 請幫忙?

我有一個網頁,可以說index.php,並且在其中包含footer.php文件。 在footer.php內部,我有一個引用腳本callback.php的表格。

在callback.php文件中,它成功提交了表單的信息並將其插入數據庫,但是當您單擊“提交”按鈕時出現了問題。

它提交,但隨后該網頁轉到腳本的頁面,該頁面為空白。 http://siteroot/scripts/callback.php ,然后說“此網頁具有重定向循環”。

這是我的代碼:

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

if ($mysqli->query("INSERT into callback_tbl (namesurname, email, phone) VALUES ('$namesurname', '$email', '$phone')")) {
echo "<script type='text/javascript'>
alert('Thank you, we will contact you as soon as possible'); 
</script>";

header( "Location: $actual_link" );
}

我什至嘗試過,但這也沒有用。

var currenturl = document.URL;
window.location.href = currenturl;

請幫忙!

那是因為$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 引用頁面本身( callback.php )。 嘗試這個:

if ($mysqli->query("INSERT into callback_tbl (namesurname, email, phone) VALUES ('$namesurname', '$email', '$phone')")) {
echo "<script type='text/javascript'>
    alert('Thank you, we will contact you as soon as possible'); 
    window.history.back();
</script>";

}

看起來這可能是由header( "Location: $actual_link" );引起的header( "Location: $actual_link" ); 並且$actual_link使其重定向到已經打開的頁面。

看這里:

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

在這里您獲得腳本的當前地址,在這里您重定向到當前地址

header( "Location: $actual_link" );

所以你有循環:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM