PHP Header Redirect in a New Window

PHP Header Redirect in a new window?

<a href='yourbannerscript.php' target='_blank'>...</a>

Header Location in new tab

No, it is not possible. The header will simply redirect the current page, in the current window/tab.

how to redirect php page with parameters into new tab or window

The php header should be :

header("location:Delivery_form.php?cnno=".$cnno."&copies=".$nocopy);

Script

echo "<script type=\"text/javascript\">
window.open('Delivery_form.php?cnno=".$cnno."&copies=".$nocopy."', '_blank')
</script>";

window.location (JS) vs header() (PHP) for redirection

The result is same for all options. Redirect.

<meta> in HTML:

  • Show content of your site, and next redirect user after a few (or 0) seconds.
  • Don't need JavaScript enabled.
  • Don't need PHP.

window.location in JS:

  • Javascript enabled needed.
  • Don't need PHP.
  • Show content of your site, and next redirect user after a few (or 0) seconds.
  • Redirect can be dependent on any conditions if (1 === 1) { window.location.href = 'http://example.com'; }.

header('Location:') in PHP:

  • Don't need JavaScript enabled.
  • PHP needed.
  • Redirect will be executed first, user never see what is after. header() must be the first command in php script, before output any other. If you try output some before header, will receive an Warning: Cannot modify header information - headers already sent


Related Topics



Leave a reply



Submit