首页 > Web开发 > 详细

<小田吃饺子> PHP:现有图片验证码类

时间:2017-09-25 18:05:21      阅读:195      评论:0      收藏:0      [点我收藏+]
<?php
class TL_Captcha_img{
    private $image; //验证码图片
    private $captch_code; //验证码信息
    public function __construct($table){
        session_start();
        if(is_array($table)){
            $index = rand(0,count($table)-1);
            //获取随机的value
            $table1 = array_keys($table);
            $value = $table1[$index];
            $_SESSION[‘authcode‘] = $this->captch_code;
            //获取随机的键值
            $key = array_flip($table);
            $key =  $key[$value];
            $this->image = dirname(__FILE__).‘/‘.$key.‘.png‘;
        }
    }
    public function __destruct() {
        $this->image = file_get_contents($this->image);
        header(‘content-type:image/png‘);
        echo $this->image;
        imagedestroy($this->image);
    }
}
// $table = array(
// 	‘sql‘ => ‘sql‘,
// 	‘png‘ => ‘png‘,
// 	‘jpg‘ => ‘jpg‘,
// 	‘gif‘ => ‘gif‘,
// 	‘css‘ => ‘css‘,
// 	‘html‘ => ‘html‘,
// 	‘js‘ => ‘js‘,
// 	‘php‘ => ‘php‘,
// 	‘txt‘ => ‘txt‘,
// 	‘word‘ => ‘word‘,
// 	‘excal‘ => ‘excal‘,
// 	‘img‘ => ‘img‘,
// );
// $Captcha_img = new Captcha_img($table);

  

<小田吃饺子> PHP:现有图片验证码类

原文:http://www.cnblogs.com/hello-tl/p/7593022.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!