myMVC_module_Captcha
1.0.0
该MYMVC模块提供了可以在自己的HTML表单中使用的验证码图像。
anadalemo.ttf )之类的真实类型字体中font.ttf CD进入myMVC3.2.x复制的模块文件夹;例如:
cd /var/www/myMVC/modules/ ;克隆myMVC_module_Captcha作为Captcha
git clone --branch 1.0.x https://github.com/gueff/myMVC_module_Captcha.git Captcha ; 1。将以下路线添加到您的主要工作模块
// captcha route
MVC Route:: GET (
Captcha Model Index:: $ sRoute ,
' CaptchaControllerIndex::index '
);2。在主要工作模块的控制器中添加验证码检查和创建
// check if captcha is valid
if ( true === Captcha Model Index:: captchaIsValid ())
{
// captcha is OK!
}
// create captcha for new
$ sCaptchaText = Captcha Model Index:: createCaptcha ();3。将此验证码添加到您的前端模板中
< form action ="" method =" post " >
<!-- captcha -->
< label for =" captcha " > Captcha </ label >
< img src =" {CaptchaModelIndex::$sRoute} " >
< input type =" text "
name =" {CaptchaModelIndex::$sPostFieldName} "
maxlength =" {CaptchaModelIndex::$iCaptchaTextLength} "
value =""
placeholder =" captcha code "
autofocus
>
<!-- /captcha -->
< button type =" submit " > submit </ button >
</ form > ?注意:确保您的路线允许POST方法
允许在您要使用验证码的路线中POST方法。
MVCRoute::MIX(
['GET', 'POST'],
'/',
'FooControllerIndex::index',
$oDTRoutingAdditional->getPropertyJson()
);
在主模块的环境中,只需更改验证码模型类的属性即可。
这是一个例子
//-------------------------------------------------------------------------------------
// Module Captcha
// load Class
require_once $ aConfig [ ' MVC_MODULES_DIR ' ] . ' /Captcha/Model/Index.php ' ;
// declare a custom route
Captcha Model Index:: $ sRoute = ' /captcha/MyFormularXY/ ' ;
// add some extra chars to choose from...
Captcha Model Index:: $ sChar .= ' _!=)(/&%$[].:,;+*~# ' ;
// ...if you changed the $sChar, do not forget to adjust sanitizing rule
Captcha Model Index:: $ sCharSanitizePattern = " /[^ \ p{L}} \ p{M} \ p{S} \ p{N} \ p{P}']+/u " ;
// auto-name template input var (name="") like Route
Captcha Model Index:: $ sPostFieldName = str_replace ( ' / ' , '' , Captcha Model Index:: $ sRoute );
// set SessionName like $sPostFieldName
Captcha Model Index:: $ sSessionName = Captcha Model Index:: $ sPostFieldName ;