0

I need to make something like this but the header location don't work when he is in a function.

How i can make a header location or something like this in a function ?

<?
function Heloo()
{
   if(1 < 2) header('Location: test2.php');

$A = 'blabla';
}

echo "Helo Word";

Heloo();

?>
Florent
  • 85
  • 8
  • 3
    you can't send headers after you've started output - http://php.net/manual/en/function.header.php – Rob G Mar 03 '16 at 22:11
  • @Hatchet I've voted as duplicate of the question that the link you shared is a duplicate of :) – scrowler Mar 03 '16 at 22:29

1 Answers1

0

For a redirect to work in PHP, you have to stop execution directly after with exit():

 header('Location: test2.php');
 exit();

Additionally, as pointed out in the comments if any text is being echoed to the page prior to the redirect, the headers will fail to be sent.

carbide20
  • 1,717
  • 6
  • 29
  • 52