We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Securimage

how to use Securimage in volt



77.7k
Accepted
answer

The question is kind of pointless, assuming you've read the Securimage quick start guide.

// form.volt
<form>
<img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" />
<input type="text" name="captcha_code" size="10" maxlength="6" />
<a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">[ Different Image ]</a>
</form>

That being said, if you want to integrate Securimage with Phalcon, you would do something like this:

  1. Register the securimage folder with the class loader
/// loader.php

// ...
$loader->registerDirs([
   <PUBLIC_DIR>.'/securimage/',
]);
// ...
  1. Explicitly start the session in controller action then validate
// MyController.php

// ...
public function formAction() {
   $this->session->start();
   if($this->request->has('captcha_code')) {
      $securimage = new Securimage();
      if($securimage->check($this->request->get('captcha_code')) == false) {
         / Client is probably a bot or clumsy human
      }
   }
}
// ...