Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-22-2012, 03:57 PM   PM User | #1
Acute Chaos
New Coder

 
Join Date: Jul 2011
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Acute Chaos is an unknown quantity at this point
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.
Acute Chaos is offline   Reply With Quote
Old 02-22-2012, 04:01 PM   PM User | #2
Rowsdower!
Senior Coder

 
Rowsdower!'s Avatar
 
Join Date: Oct 2008
Location: Some say it's everything.
Posts: 2,015
Thanks: 5
Thanked 395 Times in 388 Posts
Rowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura aboutRowsdower! has a spectacular aura about
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
Rowsdower! is offline   Reply With Quote
Old 02-22-2012, 04:20 PM   PM User | #3
Acute Chaos
New Coder

 
Join Date: Jul 2011
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
Acute Chaos is an unknown quantity at this point
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

Acute Chaos is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:19 AM.


Advertisement
Log in to turn off these ads.