redirection in php

Discussion in 'PHP' started by syedwna, Mar 13, 2007.

  1. #1
    how to redirect from one page to other in php
     
    syedwna, Mar 13, 2007 IP
  2. hextraordinary

    hextraordinary Well-Known Member

    Messages:
    2,171
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    105
    #2
    Here ya go:

    Header("Location: http://www.new_url.com/"); 
    PHP:
     
    hextraordinary, Mar 13, 2007 IP
  3. syedwna

    syedwna Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i shoot a mail once the mail goes i want to redirect tosame page
    if(mail($mail_to,$mail_sub,$mail_mesg,$mail_from))
    {

    exit;
    }
    }
     
    syedwna, Mar 13, 2007 IP
  4. syedwna

    syedwna Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i shoot a mail once the mail goes i want to redirect tosame page
    if(mail($mail_to,$mail_sub,$mail_mesg,$mail_from))
    {

    exit;
    }
    }

    i used all the redirect options above exit;
    none of them are working.
     
    syedwna, Mar 13, 2007 IP
  5. Robert Plank

    Robert Plank Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    So you're saying the mail is sending but the redirect is not working?
     
    Robert Plank, Mar 13, 2007 IP
  6. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #6
    based on the above the reason why it is not redirecting is because, once you send the mail you are exiting. Take the exit out of that if. You possibly might be looking for:

    if(mail($mail_to,$mail_sub,$mail_mesg,$mail_from))
    {
    Header("Location: http://www.new_url.com/");
    }
    else
    {
    exit;
    }


    HTH
     
    datropics, Mar 13, 2007 IP
  7. [x[x]x]

    [x[x]x] Peon

    Messages:
    813
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Remember, the Header statement has to be before the <head>!

    So:
    if(mail($mail_to,$mail_sub,$mail_mesg,$mail_from))
    {
    Header("Location: http://www.new_url.com/");
    }
    else
    {
    exit;
    }
    
    <head>
    PHP:
     
    [x[x]x], Mar 13, 2007 IP
  8. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #8
    x-x-x is right.
    Please note, if you're using the code in this way, you don't have to put <head> or other HTML code in the page, as in no case it will be shown ( if mail is sent, you got redirected; if mail not gets sent, you get an exit(), so that nothing will show up.

    I'ld suggest using this kind of code:
    <?
    if(mail($mail_to,$mail_sub,$mail_mesg,$mail_from))
    {
    Header("Location: http://www.new_url.com/");
    }
    else
    {
    echo "<b>Error:</b> The email could not be sent.";
    }
    ?>
    PHP:
     
    DeViAnThans3, Mar 13, 2007 IP
  9. [x[x]x]

    [x[x]x] Peon

    Messages:
    813
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Yeah, that's right!
    I somehow didn't see the exit; ;)
     
    [x[x]x], Mar 13, 2007 IP
  10. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #10
    good 'ole fashioned team-work, nothing beats it!
     
    datropics, Mar 27, 2007 IP