Search code examples
phpjavascripthead

Heading to another page in PHP


I was curious to know if there was another way than using javascript to make php go to another page ?

Because head only works when it is the first function to be called, so I resorted to javascript to go to another page. But php must have a similar function no ?

    <?php session_start();
      session_destroy();
      echo '<script language="JavaScript">
<!--
 window.location="home.php";
//-->
</script>';



?>

Solution

  • You have a mistake.

    header('Location: some_location.php');
    

    Needs to be the first things that's being output, meaning, if you echo anything before this, it wont work, other wise it will work.

    So just:

    header('Location: some_location.php');