Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.