简体   繁体   English

提交表单时,显示-该网页具有重定向循环

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

This is my first time I'm asking for help, after struggling for days now with this code. 这是我第一次在此代码中苦苦挣扎后寻求帮助。 I've tried everything possible, but can't seem to make it work. 我已经尝试了所有可能的方法,但是似乎无法使其正常工作。 Please help? 请帮忙?

I have a webpage, lets say index.php , and inside it I include the footer.php file. 我有一个网页,可以说index.php,并且在其中包含footer.php文件。 Inside the footer.php I have a form which reference to the script callback.php 在footer.php内部,我有一个引用脚本callback.php的表格。

Inside the callback.php file, it successfully submit the form's info and inserts it into the database, but the problem comes in when you click the submit button. 在callback.php文件中,它成功提交了表单的信息并将其插入数据库,但是当您单击“提交”按钮时出现了问题。

It submits but then the webpage goes to the script's page, which is blank. 它提交,但随后该网页转到脚本的页面,该页面为空白。 http://siteroot/scripts/callback.php and then says "This webpage has a redirect loop". http://siteroot/scripts/callback.php ,然后说“此网页具有重定向循环”。

Here is my code: 这是我的代码:

$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" );
}

I even tried, but this also didn't work. 我什至尝试过,但这也没有用。

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

Please help! 请帮忙!

That's because $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 那是因为$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; refers to the page itself ( callback.php ). 引用页面本身( callback.php )。 Try this: 尝试这个:

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>";

}

Looks as if this could be caused by the header( "Location: $actual_link" ); 看起来这可能是由header( "Location: $actual_link" );引起的header( "Location: $actual_link" ); and the $actual_link is making it redirect to the page it is already on. 并且$actual_link使其重定向到已经打开的页面。

look here: 看这里:

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

here you get your script current address and here your redirect to current address 在这里您获得脚本的当前地址,在这里您重定向到当前地址

header( "Location: $actual_link" );

so you got loop :) 所以你有循环:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM