Hi,
I am currently in the proccess of writing a script where I need to redirect the user to another page. However it is not possible for me to use the header function due to the page actually being included into a template so of course it will just error if I try it because the header has already been written. So I was wondering if there was another way that I could redirect the user without the use of the header function so that I can get this to work.

Thanks in advance to any suggestions.

    Just so you know here is the script I am trying to run:

    <?php
    session_start();
    if(!session_is_registered("auth")) {
    echo "<meta http-equiv='refresh' content=0;url='index.php?page=login'>";
    exit;
    }
    ?>
    

    I realised that I could just use the http redirect even though this may not be the best way but I still have the problem with the session not working because of it being written after html has already been written by the template and if I put it into the main template file it just ends up in a loop of sending itself back to the same page as index.php is the main file.

      chage

      echo "<meta http-equiv='refresh' content=0;url='index.php?page=login'>";

      to

      header("Location: index.php?page=login");
        talkster5 wrote:

        However it is not possible for me to use the header function due to the page actually being included into a template.

        That will not work.

          Oops... then try this instead

          echo "<script type=\"text/javascript\">window.location=\"index.php?page=login\"</script>";

            Thanks for your help with the redirect and I have fixed the session problem now as well.

              Write a Reply...