Header Redirect Question

Discussion in 'PHP' started by MrX, Apr 2, 2007.

  1. #1
    If I do a header("Location: http://xyz.com") does that get sent to the browser immediately? In other words, can I then do other stuff after the header command without worrying about delaying the redirect to the browser? Thx.
     
    MrX, Apr 2, 2007 IP
  2. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You have to do what you have to do before the header Location thing or, you can use meta refresh with a small delay.
     
    manilodisan, Apr 2, 2007 IP
    MrX likes this.
  3. Richie_Ni

    Richie_Ni Illustrious Member

    Messages:
    10,721
    Likes Received:
    1,175
    Best Answers:
    0
    Trophy Points:
    410
    #3
    Why not use htaccess redirect?
     
    Richie_Ni, Apr 2, 2007 IP
  4. MrX

    MrX Well-Known Member

    Messages:
    1,563
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Coz I need to do some processing when I do the redirect.
     
    MrX, Apr 2, 2007 IP
  5. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is not about how to better redirect. the guy wants a redirect and some code executed. How do you do that with .htaccess?
     
    manilodisan, Apr 2, 2007 IP
  6. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    code 2 be executed.....
    header("Location: somepage.php");
    exit
     
    manilodisan, Apr 2, 2007 IP
  7. Rinox

    Rinox Peon

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    htaccess is not always the best choice. In forums like phpBB the header function is used because they first need to check if for example a user is logged in or not. Then it's so much easier to use the header function.
     
    Rinox, Apr 3, 2007 IP
  8. Felu

    Felu Peon

    Messages:
    1,680
    Likes Received:
    124
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You can only modify the header before any output is sent to the browser. Else you'll need to use the META refresh.
     
    Felu, Apr 3, 2007 IP
  9. Houdas

    Houdas Well-Known Member

    Messages:
    158
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #9
    Alternatively, if you don't want to worry about outputting something before calling header(), use output buffering.
     
    Houdas, Apr 3, 2007 IP