Home  >  Article  >  Backend Development  >  回答: PHP验证框

回答: PHP验证框

WBOY
WBOYOriginal
2016-06-13 13:08:24883browse

答复: PHP验证框
以下内容节选自《PHP Web2.0开发实战》 老外写国人译的书

可以使用PEAR(PHP扩展与应用库)提供的Text_CAPTCHA组件来生成CAPTCHA图象。

先安装:可以下载,也可用pear命令
pear install Text_Password
pear install -f Text_CAPTCHA
pear install -f Image_Text

这个包依赖于另外两个,我试了一下,主要是生成随机的字符用的
还需要一个字体文件,后缀是ttf,网上很多,

            // 以下是createImage.php
            include(Text_CAPTCHA文件); //如果include路径已指向pear目录,可以没有这句话
            $captcha = Text_CAPTCHA::factory('Image'); //生成对象先
            //以下依次是大小,字库文件的路径,字库文件名
            $opts = array('font_size' => 20, 
                          'font_path' => Zend_Registry::get('config')->paths->data,
                          'font_file' => 'VeraBd.ttf');
            $phare = 自定义一个随机数;
            $captcha->init(120, 60, $phrase, $opts); //120和60是生成图片的宽和高
            //这里我选择png图片,随意,也可用jpg
            header('Content-type: image/png');
            echo $captcha->getCAPTCHAAsPng();



            //以下是test.html
            <img  src="createImage.php" alt=" 回答: PHP验证框 " >


是不是很简单?82.95.186.47:9001  850246527

 回答: PHP验证框
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article: PHP 用户登录范例 Next article: php 戏法方法汇总