Hello, Currently making a captcha, having troubles on it checking if its correct on my php process page. Code: $code = strip_tags(trim($_POST['code'])); if(!$_SESSION['captcha'] == $code) { echo "ERROR"; unset($_SESSION['captcha']); exit(); } else { //do my action } PHP: For some reason, its just always doing the action if its correct, even if i enter the wrong code. I've also echo'ed both the session and code just to check they are going through. Thanks
$code = strip_tags(trim($_POST['code'])); if($_SESSION['captcha'] != $code) { echo "ERROR"; unset($_SESSION['captcha']); exit(); } else { //do my action } PHP: You probably don't need to striptags on the _POST ... seems a pointless operation ... Code (markup):
You have to consider that ! operator has a higher precedence than ==. So if(!$_SESSION['captcha'] == $code) PHP: and if(!($_SESSION['captcha'] == $code)) PHP: will give the different results.