Zend framework generates verification code and implements verification code verification function (with demo source download) _php instance

Source: Internet
Author: User
Tags php programming zend zend framework

The example of this article describes the Zend Framework to generate the verification code and implement the Verification code verification function method. Share to everyone for your reference, specific as follows:

Today, how to implement the function of the verification code in the message book. This will help our website to reduce some spam messages or ad messages. Here is the Zend_captcha component that I have not used Zend framework to carry. I just found the authentication code class in the thinkphp frame. It was applied to the. We message the implementation of this verification code ... I am here.. is to write it as a plug-in form ... Of course the Zend Framework has many ways to use other code. I will only use one of them now ... So there are good ways for friends. We can discuss it together. Let's make progress together. Oh....

The first step: Find the Library folder in our original tutorial. This is where we used to store our Zend Class Library folder. Now we add a few folders in the Library folder to our project: library/custom/controller/plugin/

Folder we joined to complete. This time we are going to find our Captcha file. Here I name the imgcode.php file name. This file is the class file that we're going to use to generate the captcha. Of course this file is rewritten as a plugin form in the Zend Framework ... The imgcode.php section documents are as follows:

//imgcode.php Part of Program Description
//program generated verification code data
$randval = $this->rand_string ($length, $mode);
Storage of
This data in zend_session ... Here is a session namespace problem, friends can go to look at the manual
$authCode = new Zend_session_namespace (' Auth_code ');
$authCode->imagecode = $randval;
? >

Step two: In our message in the controller (indexcontroller.php), add a following action (action). This action is to generate verification of the application.

The program looks like this:

<?php Public
function imgcodeaction () {
$this->getfrontcontroller ()->setparam (' Noviewrenderer '), true);
Call our verification code class
Zend_loader::loadclass (' Custom_controller_plugin_imgcode ');
$imagecode =new Custom_controller_plugin_imgcode ();
Return to the code picture
$imagecode->image2 ()

The third step: in our message template to add the function of the Verification code: Open the message this Display page template, message/index.phtml we fill in the message area to add the following HTML code. This time please see the source file inside the JS code. Like replacing the verification code picture what the function. I won't say much of this little thing. I just have a few more JS features than the last tutorial.

At last.. is to find the Messageaction function in our controller (indexcontroller.php). We add the ability to use the verification code inside. That is, verify that the user filled in the verification code and we exist in the session inside the verification code is the same. If the same. We let him leave a message. Otherwise, don't let him leave a message. I think we all have this basic idea.

Full instance code click here to download the site.

More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with your PHP programming based on the Zend Framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.