user1509201
user1509201

Reputation: 99

PHP header redriction to new page

I would like to click on a hyperlink which will go to page 2, but I also want to open a new blank page.

I tried:

header "Location: http://bing.com";
header ("Location: http://bing.com", false);
header ("Location: http://bing.com", true, 301);

I'd like to use only php to open the new blank page.

Upvotes: 2

Views: 27190

Answers (5)

Xtreme
Xtreme

Reputation: 1

This is my code for new tab and its working perfectly. Just only care about your file location.

CODE:

<?php 
          if(isset($_POST['button']))
             {
                echo '<script language="javascript">';
                 echo 'window.open( "/Projectfolder/File.php" )';
                 echo '</script>';
              }
          ?>  

Upvotes: 0

Himanshu Goel
Himanshu Goel

Reputation: 1

One of the perfect solution to it which I found here only and you can do one thing is that which page you want to open along with other one put the code below in a PHP page the one needs to be opened and this code will pop up for the link provided in place of default link.

<?php
echo "<script type=\"text/javascript\">  window.open('http://reliable4you.com/', '_blank')  </script>";
?>

Upvotes: 0

Jordan Mack
Jordan Mack

Reputation: 8733

You cannot open a new window from doing a header redirection. You must use Javascript.

If you need to do it with PHP for some reason, you could print the Javascript like this:

<?php
echo '<script>window.open("http://www.google.com/");</script>';
?>

Upvotes: 2

Marcin Orlowski
Marcin Orlowski

Reputation: 75647

You cannot do this from the header redirection. You need target="_blank" attribute added to your <A> in HTML. Or do the trick where your redirection redirects to the page that would use JavaScript to do that for you (expect it to be blocked by the browsers anti-popup feature though)

Upvotes: 4

Evert
Evert

Reputation: 99618

This is not possible with PHP. If you want to open 2 pages at once (replace the current, and open a second tab/window) you must do this with javascript.

Upvotes: 0

Related Questions