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 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Captcha validation not working

    I have a simple login form - user name, password, captcha code field and a submit. It is fine and good to go.

    I have separate file creating the captcha image and setting a Session with the captcha code in it. It is fine and good to go.

    I have the third file that executes everything.

    If I log in accurately everything works well.

    I have validation for the three fields in the form:

    Code:
    	$name = clean($_POST['name']);
    	$pass = clean($_POST['password']);
    	$capcode = clean($_POST['security']);
    	$code = $_SESSION['security_code'];
    
    
    	if($name == '') {
    		$errmess_arr[] = 'Your username was missing';
    		$erralert = true;
    	}
    	if($pass == '') {
    		$errmess_arr[] = 'Your password was missing';
    		$erralert = true;
    	}
    	if($capcode == '') {
    		$errmess_arr[] = 'You need to fill in the security code';
    		$erralert = true;
    	}
    	if( strcmp($capcode, $code) != 0 ) {				
    		$errmsg_arr[] = 'The security code you entered did not match the security code showing. Please try again.';
    		$erralert = true;
    	}	
    	if($erralert) {
    		$_SESSION['error'] = $errmess_arr;
    		session_write_close();
    		header("location: loginfail.php");
    		exit();
    	}

    If I miss filling in any one, two or all three of the fields the validation works perfectly.

    BUT if the code filled in doesn't match the captcha image I don't get the alert message. It doesn't log in the way it shouldn't if the code is wrong, all that code works fine. But I've been banging my head against the wall trying to figure out why the comparison validation message doesn't show up like the rest do.

    I echoed the session to see if it was setting right and it is.

    EVERYTHING works the way it should except for this.

    The user is redirected to the right page but the message doesn't display like it does for the other validation checks.

    Any ideas? Let me know if you need the rest of the code but I thought this would be enough.

    Thanks.

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    A second set of eyes never hurts. You're going to kick yourself:

    Code:
    	if( strcmp($capcode, $code) != 0 ) {				
    		$errmsg_arr[] = 'The security code you entered did not match the security code showing. Please try again.';
    		$erralert = true;
    	}
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    You know how many $%^& times I looked at that.

    I double checked I had that right so many times and and just glazed over it because mess=message msg=message ...

    Thanks a lot - lol. That is the problem with working on your own sometimes. A fresh set of eyes can take 15 seconds to save you a couple hours.

    Thanks for your help!

    Of course it works now - btw



  •  

    Posting Permissions

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