开发应用中验证码是少不了的,我们经常会碰以关于被机器注册,那么有了验证码可以有效的防止这类行为,下面我们来看看我提供的这款代码,实例代码如下:
-
<?php
-
session_start();
-
class authnum {
-
-
private $im;
-
private $im_width;
-
private $im_height;
-
private $len;
-
-
private $randnum;
-
private $y;
-
private $randcolor;
-
-
public $red=238;
-
public $green=238;
-
public $blue=238;
-
-
-
-
-
-
public $ext_num_type='';
-
public $ext_pixel = false;
-
public $ext_line = false;
-
public $ext_rand_y= true;
-
function __construct ($len=4,$im_width='',$im_height=25) {
-
-
$this->len = $len; $im_width = $len * 15;
-
$this->im_width = $im_width;
-
$this->im_height= $im_height;
-
$this->im = imagecreate($im_width,$im_height);
-
}
-
-
function set_bgcolor () {
-
imagecolorallocate($this->im,$this->red,$this->green,$this->blue);
-
}
-
-
function get_randnum () {
-
$an1 = 'abcdefghijklmnopqrstuvwxyz';
-
$an2 = 'abcdefghijklmnopqrstuvwxyz';
-
$an3 = '0123456789';
-
if ($this->ext_num_type == '') $str = $an1.$an2.$an3;
-
if ($this->ext_num_type == 1) $str = $an1;
-