Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Headers not pushing on a true statement

    I am setting up a basic reigstration page. I have been out of coding for alittle with now. I basically wanted to setup checks for valid data at the registration page however it just submits the query and runs any of the checks sucessfully. Any idea's?

    PHP Code:
    <?php
    require '/include/headerdb.php';



    $username $_POST['username'];
    $email $_POST['email'];
    $fname $_POST['fname'];
    $lname $_POST['lname'];
    $vcode rand(10000000009999999999);
    $password $_POST['password'];
    $vpassword $_POST['vpassword'];

    if (
    $password != $vpassword) {
        
    header("Location: register.php?error=1");
    }
    if (
    $username == "") {
        
    header("Location: register.php?error=4");
    }
    if (
    $email == "") {
        
    header("Location: register.php?error=5");
    }
    if (
    $fname == "") {
        
    header("Location: register.php?error=6");
    }
    if (
    $lname == "") {
        
    header("Location: register.php?error=7");
    }
    if (
    $password == "") {
        
    header("Location: register.php?error=8");
    }



    $verquery mysql_query("SELECT * FROM users");
    while (
    $verarray mysql_fetch_array($verquery)) {
        if (
    $username == $verarray['username']) {
            
    header("Location: register.php?error=2");
        }
        if (
    $email == $verarray['email']) {
            
    header("Location: register.php?error=3");
        }
      }


    $newquery mysql_query("INSERT INTO users (username, password, fname, lname, vcode, email)
        VALUE ('$_POST[username]','$_POST[password]','$_POST[fname]','$_POST[lname]','$vcode','$email')"
    );

    if (!
    $newquery) {
         
    header("Location: register.php?error=3");
    } else {
         
    header("Location: regcomplete.php");
    }



    ?>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You're not doing anything to stop it from processing. Any call to a header() only pushes the header onto the stack; it doesn't do anything to stop the page from processing. If you want it to halt processing at that point, call an exit or die.
    The above can be simplified by only providing the error code associated with it to a tracked variable, and if the tracked variable is > 0, push a header for the location and call exit.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    horan1616 (03-17-2010)

  • #3
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    THANK YOU!

    Completely forgot about having to use die(header(***));


  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Do not use die(header(...)). It won't actually trigger errors since its not wrong, but it doesn't make any logical sense. Die should only have an argument if its either a string or an integer indicating error codes. Header is always void. Instead, you should be running with a:
    PHP Code:
    header("Location: ....");
    exit(
    0); // 0 is the default, can be called as: exit; or exit(); as well. 
    Since you're script terminates successfully (which coincidentally is the same result you'd get by wrapping a header with a die).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •