Jump to content

Session IF


a1amattyj

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/107189-session-if/
Share on other sites

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)) {

 

Link to comment
https://forums.phpfreaks.com/topic/107189-session-if/#findComment-549573
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.