PHP中验证码类及使用方法
备注:将公共页面加入session_start();
<?php
session_start();
ini_set('display_errors', 'Off');
class CCheckCodeFile
{
//验证码位数 www.2cto.com
var $mCheckCodeNum = 4;
//产生的验证码
var $mCheckCode = '';
//验证码的图片
var $mCheckImage = '';
//干扰像素
var $mDisturbColor = '';
//验证码的图片宽度
var $mCheckImageWidth = '80';
//验证码的图片宽度
var $mCheckImageHeight = '20';
//输出头
function OutFileHeader()
{
header ("Content-type: image/png");
}
//产生验证码
function CreateCheckCode()
{
//$this->mCheckCode = strtoupper(substr(md5(rand()),0,$this->mCheckCodeNum));
$this->mCheckCode = strtoupper(substr(rand(0,9999999999),0,$this->mCheckCodeNum));
session_cache_expire(60);
session_start();
$_SESSION["code_str"] = $this->mCheckCode;
return $this->mCheckCode;
}
//产生验证码图片
function CreateImage()
{
$this->mCheckImage = @imagecreate ($this->mCheckImageWidth,$this->mCheckImageHeight);
imagecolorallocate ($this->mCheckImage, 255, 255, 255);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>