0

I'm inhering some code and trying how to redirect properly.

There's an iframe that's PHP within an HTML page.

When the PHP executes (gets form submit and sends an email), the iframe successfully redirects correctly, using:

header('Location:http://www.example.com');

What's the best way to do this?

I need something like window.top.location.href = "http://www.example.com"; but in PHP (I think)

jonmrich
  • 4,233
  • 5
  • 42
  • 94
  • 1
    The iframe, is redirected by the server (via PHP, a 302/Location header) can only change the URL of the iframe. You could have PHP respond with JavaScript *in* the iframe that would redirect. It would be "window.top.location='foo.html'" or similar. – Kevin_Kinsey Oct 28 '16 at 16:09

1 Answers1

9

There's no way to do this with raw PHP - HTTP headers can't trigger something on the parent like that, so you'r stuck with something like:

<?php echo "<script>window.top.location.href = \"http://www.example.com\";</script>"; ?>
ceejayoz
  • 176,543
  • 40
  • 303
  • 368