Monthly Archives: February 2014

Get Your PHP Elephant Toy


I’ve found this cool site where you can buy a PHP elephant of your choice. This may be a great gift for your collegue or friend.

The link:


Leave a comment

Filed under Uncategorized

Unusual FIGlet CAPTCHA in ZF2

In a web form, you sometimes need to use a CAPTCHA test. A CAPTCHA (stands for “Completely Automated Public Turing test to tell Computers and Humans Apart”) is a challenge-response test used in web sites for determining whether the user is a human or a robot.

A typical CAPTCHA test works using the following algorithm:

  1. Some secret sequence of characters (word) is generated server-side.
  2. The secret word is saved in a PHP session variable.
  3. The distorted image is generated based on the secret word.
  4. The image is then displayed on the web page to site user.
  5. The site user is asked to type characters shown on the image.
  6. If the characters typed by user are the same as the secret word
    saved in the session, the test is considered passed.

The CAPTCHA test allows to reliably distinguish humans from robots, because humans are easily able to recognise and reproduce characters from the distorted image, while robots are not (at the current stage of evolution of computer vision algorithms).

In Zend Framework 2, there are several types of CAPTCHA. The most widely used one requires that the user type the letters of a distorted image that is shown on the web page. But, in this post, I’d like to tell about an unusual CAPTCHA type called the Figlet CAPTCHA.

To add the Figlet CAPTCHA to your form model, call the form’s add()
method as follows:

namespace Application\Form;
// ...

class MyForm extends Form
    // ...    
    protected function addElements() {
        // ...         
        // Add the CAPTCHA field
          'type'  => 'captcha',
          'name' => 'captcha',
          'attributes' => array(                                                
          'options' => array(
            'label' => 'Human check',
            'captcha' => array(
                'class' => 'Figlet',
                'wordLen' => 6,
                'expiration' => 600,                     

Above, the captcha key of the configuration array (see line 19) contains the following
parameters for configuring the Figlet CAPTCHA algorithm attached to the form element:

  • the class parameter (line 20) should be either the full CAPTCHA adapter
    class name (\Zend\Captcha\Figlet) or its short alias (Figlet).

  • the wordLen parameter (line 21) defines the length of the secret word to be generated.

  • the expiration parameter (line 22) defines the CAPTCHA expiration period (in seconds).

To render the CAPTCHA field, add the following lines to your .phtml
view template file:

  <?php echo $this->formLabel($form->get('captcha')); ?>
  <?php echo $this->formElement($form->get('captcha')); ?>
  <?php echo $this->formElementErrors($form->get('captcha')); ?>

Now, open the web page in your web browser. Once that is done,
you should see a page like in the figure below.


Once the PHP renderer processes the view template, it generates HTML markup for
the CAPTCHA element like shown below:

  <label for="captcha">Human check</label>            
 __   _    __   __   _    _      ___     _    _    __   __  
| || | ||  \ \\/ // | \  / ||   / _ \\  | || | ||  \ \\/ // 
| '--' ||   \ ` //  |  \/  ||  | / \ || | || | ||   \ ` //  
| .--. ||    | ||   | .  . ||  | \_/ || | \\_/ ||    | ||   
|_|| |_||    |_||   |_|\/|_||   \___//   \____//     |_||   
`-`  `-`     `-`'   `-`  `-`    `---`     `---`      `-`'   
<input name="captcha[id]" type="hidden" value="b68b010eccc22e78969764461be62714">
<input name="captcha[input]" type="text">                              
<p class="help-block">Enter the letters above as you see them.</p>

Note: This post is an excerpt from Chapter 8 “Advanced Usage of Forms” of my book “Using Zend Framework 2“.

Leave a comment

Filed under Zend Framework 2

Launching Official “Using Zend Framework 2” Book Web Site


Recently, I’ve launched the dedicated web site for my programming book “Using Zend Framework 2”.

The link:

There I plan to add video tutorials, reader reviews, news, announcements, etc. I would like to say thanks to Edu Torres, a 2D artist from Spain for making the design for the web site.

Leave a comment

Filed under Uncategorized

Becoming a Zend Certified Engineer

This week I watched a webinar “Excellerate your career with Zend Certifications” about Zend Certification. The certification allows to get direct benefits to those who develop web sites with PHP/Zend Framework. Once you have certified, you are able to greatly increase your salary and get a competitive advantage when looking for a new job.

The testing is administered by Pearson VUE centers worldwide. You have 70 questions and 90 minutes to answer them. The goal of the test is to ensure you know the minimum required basics in PHP or Zend Framework. You don’t need to memorize all the PHP documentation (or Zend Framework reference guide), instead, you need to know how code works and what output to expect for certain input. 

Once you submit the answers, you immedieatelly get the results (either you passed the test, or not). As you pass the test, you become a Zend Certified Engineer (ZCE). This title is given for life, and you don’t need to renew it. With the ZCE title, you also get some nice things, such as a “perpetual” copy of Zend Studio IDE, an ability to use the  “Zend Certified Engineer” logo in your CV or resume and a ZCE sticker to put on your laptop 🙂

Leave a comment

Filed under PHP, Zend Framework 2