Header Location

Discussion in 'PHP' started by encom, Jul 5, 2009.

  1. #1
    Hi,

    Is there a way or a different function that would allow me to send the user to another page.

    (to my understanding, header location can only be used before output and is usless for my script)

    thanks.
     
    encom, Jul 5, 2009 IP
  2. Dox5

    Dox5 Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The easiest way would be with something like Java, as php is run before the page is displayed. The only way i can think of doing it with php is to refresh/reload the page and then redirect.
     
    Dox5, Jul 5, 2009 IP
  3. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #3
    if u use the function obstart() then you can send the headers later aswell
     
    Bohra, Jul 5, 2009 IP
  4. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <meta http-equiv content="timeinseconds;url=redirect url here">

    or

    <script type="text/javascript">
    <!--
    window.location = "redirect url here"
    //-->
    </script>
     
    SHOwnsYou, Jul 6, 2009 IP
  5. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #5
    This has worked for me well.
     
    samyak, Jul 6, 2009 IP
  6. www.amagit.com

    www.amagit.com Peon

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    For PHP... before you've written to the page:

    <?php header("Location: http://www.example.com/");?>
    Code (markup):
    You said that it is useless because you send output too soon... couldn't you possibly check if you must redirect before any output and then redirect right away?

    Javascript is not always the best way because you can't be guaranteed that your user has it enabled, although the vast majority do.
     
    www.amagit.com, Jul 6, 2009 IP
  7. hassanahmad2

    hassanahmad2 Active Member

    Messages:
    243
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #7
    Use buffered output as bohra said earlier, its the only way through which you can call the header function later.
     
    hassanahmad2, Jul 7, 2009 IP