1

I am wondering if it is possible to call a script through a redirect. I have a contact form using PHP mail that echos a redirect back to the home page, like so;

...
header("Location: ../index.php");
...

Is it possible to add an onload event that gets passed to the redirected page? So when "index.php" is loaded from the redirect it calls a pop up thank you or something like that.

Be Right Bacon
  • 75
  • 1
  • 3
  • 9

1 Answers1

0

If you're sending them to the next page like this, you could either append some instructions to the end of the url, or you could store them in a session variable and check that upon the next page load - or even a combination of both.

session_start();

$_SESSION["redirect_url"] = "options.html";

header("Location: ../index.php?redirected=1");

And perform some type of check on the new landing page:

session_start();

if ( $_GET["redirected"] && $_SESSION["redirect_url"] ) {
  echo "<script>
          window.onload = function(){
            var myWin = window.open( '" . $_SESSION["redirect_url"] . "' );
          };
        </script>";
}
Sampson
  • 265,109
  • 74
  • 539
  • 565