'PHP Header Redirect in a new window?

For a banner management system i use a

 header("Location: http://www.awebsite.com");

to redirect to the proper website. Is it possible to force this header script to open in a new window?



Solution 1:[1]

No. If you want a new window, you have to deliver the redirect as HTML/Javascript.

Solution 2:[2]

This works for me

echo "<script>window.open('yoursite.com');</script>";

Solution 3:[3]

It would be nasty, and might not be want you want, but including an IFRAME tag pointing to a php file with the header redirect could be a solution. Doesn't create a new window, but creates a window-within-a-window.

<iframe src="/myredirectscript.php"></iframe>

Solution 4:[4]

You should redirect to a page with a redirect metà tag like the one on the most voted answer at Open HTML meta redirect in new window

So the page you redirect your headers to will contain a metà tag with:

<meta http-equiv="refresh" />
<meta content="0; URL=javascript:window.open('http://uri.of
.your.pagewhereyouwabtoredirect/path','_parent');"/>

Solution 5:[5]

It's Not possible.. Instead of that you can set open new tab in form attribute target="_blank"

 <form target="_blank" method="post" action="contact-function.php">

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chaos
Solution 2
Solution 3
Solution 4 Naveen DA
Solution 5 sabithkumar