a1amattyj Posted May 25, 2008 Share Posted May 25, 2008 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 } 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 Quote Link to comment https://forums.phpfreaks.com/topic/107189-session-if/ Share on other sites More sharing options...
BlueSkyIS Posted May 25, 2008 Share Posted May 25, 2008 do you have session_start() at the top of each page? Quote Link to comment https://forums.phpfreaks.com/topic/107189-session-if/#findComment-549570 Share on other sites More sharing options...
.josh Posted May 25, 2008 Share Posted May 25, 2008 Also, as far as your condition logic goes: basically what you're doing is saying if (NULL == $code) because whether the session variable is passed or not, or is correct or not, or whatever, the ! in front of it implies it not existing, so your condition is based on it not existing. You need to change that to if($_SESSION['captcha'] != $code) { or if ((!$_SESSION['captcha']) or ($_SESSION['captcha != $code)) { Quote Link to comment https://forums.phpfreaks.com/topic/107189-session-if/#findComment-549573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.