Skip to content
PHP Logo

How can the target="_blank" attribute be added to a header('Location:../login.php'); command in PHP?

When using the header('Location:../login.php'); command in PHP to redirect to a new page, it does not allow for adding the target="_blank" attribute to open the new page in a new tab or window. To achieve this, you can use JavaScript in conjunction with PHP to open the new page in a new tab.

php
<?php
echo '<script>window.open("../login.php", "_blank");</script>';
exit;
?>