We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36467
    • 73 Posts
    I am using custom captcha script
    <img src='http://www.abc.com/assets/captcha.php' >
    Captcha is getting displayed properly thats not the problem.But we know that captcha script stores the generated "word" in session. But when i print session i cant find it in session array. [ed. note: amitpatil last edited this post 14 years, 1 month ago.]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Where is the code that inserts the captcha word into the SESSION?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 36467
        • 73 Posts
        u can see img tag is having src attribute which calls captcha.php, I tried that captcha script outside of modx and its working fine, no doubt about it. I even crosschecked the captcha.php file code and session variable assignment is also there
        $_SESSION[$this->session_var] = $text;

          • 36467
          • 73 Posts
          I made few changes to captcha.php to debug its working, and called that url directly from browsers address bar like this http://www.abc.com/assets/captcha.php?0.881588743716511
                  $_SESSION[$this->session_var] = $text;
                  print_r($_SESSION);
          

          I can see its storing the value in session
          Array ( [captcha] => disclike ) 
          


          Does modx flushesh session in between ??
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            I'm not sure about that; it shouldn't. However, if you are using a custom snippet, is it possible that the default MODx captcha system is overwriting your value?
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 36467
              • 73 Posts
              Actually i am not using captcha system made for modx its normal captcha, here is the link http://code.google.com/p/cool-php-captcha/
                • 3749
                • 24,544 Posts
                Probably the most secure thing you can do is use the MODX Captcha with the mathstring option turned on. At least you might try the MODX captcha and see if it saves the session data properly.


                ------------------------------------------------------------------------------------------
                PLEASE, PLEASE specify the version of MODX you are using.
                MODX info for everyone: http://bobsguides.com/modx.html
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 36467
                  • 73 Posts
                  Before using third party captcha i gone through modx adone's i found one captcha plugin but it says "Its for manager only"
                    • 36467
                    • 73 Posts
                    I have installed captcha plugin, can u please tell me how to call that in form ??
                      • 3749
                      • 24,544 Posts
                      Here is what SPForm uses (modified somewhat):

                      spfCaptchaTpl Tpl chunk:

                      <div class="spf_captcha_instructions">[[+spf-captcha-instructions]]</div>
                      
                      <div class="spf_captcha_image">[[+spf-captcha-image]]</div>
                      
                      <div class="spf_input_pair">
                          <span class="spf_block_prompt">[[+spf-captcha-input-prompt]]</span>
                          <span class="spf_normal_input">[[+spf-captcha-input]]</span>
                      </div>
                      


                      Snippet code:

                       /*   make sure we can  find the captcha files   */
                      
                              if (! file_exists($this->modx->getOption('assets_path'). "components/captcha/captcha.php")) {
                                echo '
                      ' . $this->modx->lexicon('no-captcha');
                                exit();
                              }
                              $useMathString = $this->modx->getOption('useMathString',$this->spfconfig,true);
                      
                              if ($useMathString) {
                                  $alt = $this->modx->lexicon("login_mathstring_message");
                              } else {
                                 $alt = $this->modx->lexicon("login_captcha_message");
                              }
                      
                              if ($useMathString) {
                                  $_SESSION['captcha.use_mathstring'] = 'true';
                                  $captcha_prompt = $this->modx->lexicon("login_mathstring_message");
                                  $captcha_input_prompt = $this->modx->lexicon("captcha_mathstring_code").":";
                              } else {
                                  $_SESSION['captcha.use_mathstring'] = 'false';
                                  $captcha_prompt = $this->modx->lexicon("login_captcha_message");
                                  $captcha_input_prompt = $this->modx->lexicon("captcha_code") . ":";
                              }
                      
                              $captcha_image= '<img '. 'onclick="this.src=' . "'" . $this->modx->getOption('assets_url') . "components/captcha/captcha.php?rand='" .
                                  "+Math.floor(Math.random()*200);".'"' .' src="'. $this->modx->getOption('assets_url') . 'components/captcha/captcha.php?rand='.rand().'" alt="'.$alt.'" />';
                      
                              $this->placeholders['spf-captcha-instructions'] = $captcha_prompt;
                              $this->placeholders['spf-captcha-image'] = $captcha_image;
                              $this->placeholders['spf-captcha-input-prompt'] = $captcha_input_prompt;
                              $this->placeholders['spf-captcha-input'] = '<input type="text" name="verify"  value="" />';
                      
                              $spfCaptchaTpl = $this->modx->getOption('spfcaptchaTpl',$this->spfconfig,'spfcaptchaTpl');
                              $this->placeholders['spf-captcha-stuff'] = $this->modx->getChunk($spfCaptchaTpl);
                      
                              return $this->modx->getChunk($spfCaptchaTpl, $this->placeholders);
                      
                      


                      Basic Verification code (assumes that the name of your Captcha input field is 'verify'):

                      if($_SESSION['veriword'] !=  $_POST['verify']) {
                                 /* failure */
                                  if ($MyDebug)) {
                                      echo "Session: " . $_SESSION['veriword'] . '
                      ';
                                      echo "Post: " . $_POST['verify'] . '
                      ';
                                  }
                      } else {
                          /* success */
                      }


                      Note that you can turn the mathstring option on with this in the snippet tag:

                      &useMathString = `1`


                      Also, this code is inside a class, so you'll have to get rid of $this-> if you're not using it inside a class.



                      ------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using.
                      MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 1 month ago.]
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting