Captcha (automatic distinction between computer and human Turing Test-completely Automated public Turing test to tell Computers and humans Apart, abbreviated as Captcha) commonly known as CAPTCHA, is a public automatic program that distinguishes users from computers and people. In the CAPTCHA test, a computer that acts as a server automatically generates an issue that is answered by the user. This problem can be generated and judged by a computer, but only humans can answer it. Since the computer is unable to answer the CAPTCHA question, the user who answers the question can be considered human.
The YII framework provides classes Ccaptcha and ccaptchaaction to support verification codes, note that this feature requires PHPGD extension support and can be queried through Yii's requirements application:
If warning is displayed, you can open the feature by installing the GD extension Library and modifying php.ini.
Ccaptcha also provides method ccaptcha::checkrequirements () to detect if the GD library is installed.
This example adds CAPTCHA functionality to the Yii Framework Development Tutorial (starrating) UI component by modifying it, and the user score is valid only if the verification code entered is correct, avoiding automatic scoring by the machine.
The first is to modify the Datamodel, add a property verifycode to hold the user input verification code, and add Ccaptchavalidator validation.
Classdatamodel extends Cformmodel{public $rating;p ublic $verifyCode;p ublic function rules () {return Array (array (' Rating,verifycode ', ' safe '), Array (' Verifycode ', ' captcha ', ' AllowEmpty ' =>! Ccaptcha::checkrequirements ()),);}}
Then modify the Sitecontroller, add the actions method, and the Captcha component defaults to ccaptchaaction with the default ID of CAPTCHA.
Public function actions () {return array (' Captcha ' =>array (' class ' = ' Ccaptchaaction ',)});
You can add the CAPTCHA component to the view below:
Beginwidget (' Cactiveform ');? >errorsummary ($model);? >widget (' Cstarrating ', Array (' model ' = $model, ' Attribute ' = ' rating ', ' name ' = ' rating ', ' value ' =>3, '); >label ($model, ' Verifycode ')?> widget (' Ccaptcha '); ? >textfield ($model, ' Verifycode ')? >endwidget ();?>
The above is the content of the PHP Development Framework Yii Framework Tutorial (CAPTCHA) UI component sample, more about topic.alibabacloud.com (www.php.cn)!