InitPHP (A PHP Framework) 用户手册
第6章 6.7.18 验证码增强类

接口描述:

验证码增强类。属于InitPHP框架扩展类,需要通过$this->getLibrary()方法获取

使用方法:

$captcha = $this->getLibrary('captcha'); 
				// 配置
                $config = array('font' => ROOT . '/data/font/' . mt_rand(0, 7) . '.ttf');
                $param = $this->controller->get_gp(array('width', 'height', 'length', 'size'));
                foreach ($param as $key => $val) {
                    $val = (int) $val;
                    if (0 < $val) {
                        $config[$key] = $val;
                    }
                }
                unset($param, $key, $val);

                // 最小要求
                if (isset($config['length']) && 4 > $config['length']) {
                    unset($config['length']);
                }
                if (isset($config['width']) && 240 < $config['width']) {
                    unset($config['width']);
                }
                if (isset($config['height']) && 80 < $config['height']) {
                    unset($config['height']);
                }

                // 获取 captcha
                $_SESSION['captcha'] = $this->getLibrary('captcha')->get($config);
                unset($config);