gueff/phimcap
最新稳定版本:1.0.0
Composer 安装命令:
composer require gueff/phimcap
包简介
phimcap provides a captcha image you could use in your own html forms.
README 文档
README
this class provides a captcha image you could use in your own html forms.
Requirements
- Linux
- php >=7.4
- GD Library extension
- existance of a true type font like
FreeMono.ttf
Install
{
"require": {
"gueff/phimcap":"1.0.*"
}
}
How to use
... a forgotPassword - Example using myMVC 3.2.x
assuming your primary working Module is called Foo:
1) dealing with html form
create a MIX /forgotPassword/ route, leading to \Foo\Controller\Index::forgotPassword
\MVC\Route::MIX( ['GET', 'POST'], '/forgotPassword/', '\Foo\Controller\Index::forgotPassword', $oDTRoutingAdditional ->set_sLayout($sTheme . '/Frontend/layout/index.tpl') ->set_sContent($sTheme . '/Frontend/content/forgotPassword.tpl') ->getPropertyJson() );
\Foo\Controller\Index::forgotPassword: create new captcha text & save to Session
public function forgotPassword() { // grab for POSTed captcha; sanitize $sCaptcha = substr( preg_replace("/[^\\p{L}\\p{N}']+/u", '', get($_POST['captcha'])), 0, strlen(Session::is()->get('mymvc.captcha')) ); if ( ($sCaptcha === Session::is()->get('mymvc.captcha')) ) { // stuff... } // create new captcha text & save to session $sCaptchaText = \Phimcap::text(); Session::is()->set('mymvc.captcha', $sCaptchaText); $sContent = $this->oView->loadTemplateAsString('/Frontend/content/forgotPassword.tpl'); $this->oView->assign('sContent', $sContent); }
template /Frontend/content/forgotPassword.tpl
<form action="" method="post"> <label for="captcha">Captcha</label> <img src="/captcha/"> <input type="text" name="captcha" id="captcha" class="form-control" value="" maxlength="5" placeholder="captcha code" > </form>
2) serving the captcha image
create \Foo\Controller\Index::captcha
public function captcha() { \Phimcap::image( Session::is()->get('mymvc.captcha') ); }
- here the captcha text for the image is taken from session
create a /captcha/ route, leading to \Foo\Controller\Index::captcha
\MVC\Route::GET( '/captcha/', '\Foo\Controller\Index::captcha' );
So the captcha image is callable via
<img src="/captcha/">
Customizing
using different Font
Phimcap uses /usr/share/fonts/truetype/freefont/FreeMono.ttf,
which is likely to be installed by default on Ubuntu Linux systems.
If you want a different Font, add the absolute path as second parameter:
\Phimcap::image( Session::is()->get('mymvc.captcha'), '/usr/share/fonts/truetype/msttcorefonts/andalemo.ttf' );
text length
per default the text length is set to 5.
you can change it to a value between 5 up to 10 by adding a value as parameter.
$sCaptchaText = \Phimcap::text(10);
统计信息
- 总下载量: 1.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2023-05-07