简体   繁体   中英

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. Inside the footer.php I have a form which reference to the script 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.

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

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]"; refers to the page itself ( 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" ); and the $actual_link is making it redirect to the page it is already on.

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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