redirect if variable is not set

Discussion in 'PHP' started by mnymkr, Aug 4, 2007.

  1. #1
    I have a simple form for leads, if can I redirect the mail.php page back to the form if a varialbe is not set?
     
    mnymkr, Aug 4, 2007 IP
  2. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like this should work

    <?php
      if (!isset($_POST['variable_name'])) {
        header('Location: http://www.yourdomain.com/mail.php');
      }
    ?>
    PHP:
     
    ErectADirectory, Aug 5, 2007 IP
  3. Dr Small

    Dr Small Guest

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You don't have to use the isset command, you could just say !$_POST['variable_name']

    <?php
    if(!$_POST['varible_name'])
          {
           header("Refresh: 0; url=http://siteurl.com/mail1.php");
          }
    ?>
    PHP:
     
    Dr Small, Aug 5, 2007 IP
  4. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #4


    and this will work with any browser?

    thansk a ton. sometimes things are more simple than i think
     
    mnymkr, Aug 5, 2007 IP
  5. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is a server side redirect, browser types don't matter.

    enjoy!
     
    ErectADirectory, Aug 5, 2007 IP
  6. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #6
    Beware of the headers already sent error that sometimes comes up. Just make sure you don't output anything before you issue a header redirect.
     
    exodus, Aug 6, 2007 IP