Practical PHP code type (_php) tutorial

Source: Internet
Author: User
Development of the application of the verification code is not necessary, we often touch on the machine registration, then have a verification code can effectively prevent such behavior, let's look at the code I provide.

Development of the application of the verification code is not necessary, we often touch on the machine registration, then have a verification code can effectively prevent such behavior, let's look at the code I provide.

Session_Start ();
Class Authnum {
Picture object, width, height, captcha length
Private $im;
Private $im _width;
Private $im _height;
Private $len;
Random string, y coordinate value, random color
Private $randnum;
Private $y;
Private $randcolor;
Red, green and blue background color, light gray by default
Public $red = 238;
Public $green = 238;
Public $blue = 238;
/**
* Optional Settings: Verification code type, interference point, interference line, y-axis random
* Set to False indicates not enabled
**/
The default is case-number mixed, 1 2 3 for lowercase, uppercase, and numeric
Public $ext _num_type= ';
Public $ext _pixel = false; Interference Point
Public $ext _line = false; Interference Line
Public $ext _rand_y= true; Y-Axis random
function __construct ($len =4, $im _width= ", $im _height=25) {
Verification code length, image width, height is the data required to instantiate the class
$this->len = $len; $im _width = $len * 15;
$this->im_width = $im _width;
$this->im_height= $im _height;
$this->im = imagecreate ($im _width, $im _height);
}
Set picture background color, default is light gray background
function Set_bgcolor () {
Imagecolorallocate ($this->im, $this->red, $this->green, $this->blue);
}
Get random numbers of arbitrary digits
function Get_randnum () {
$an 1 = ' abcdefghijklmnopqrstuvwxyz ';
$an 2 = ' abcdefghijklmnopqrstuvwxyz ';
$an 3 = ' 0123456789 ';
if ($this->ext_num_type = = ") $str = $an 1. $an 2. $an 3;
if ($this->ext_num_type = = 1) $str = $an 1;
if ($this->ext_num_type = = 2) $str = $an 2;
if ($this->ext_num_type = = 3) $str = $an 3;
for ($i = 0; $i < $this->len; $i + +) {
$start = rand (1,strlen ($STR)-1);
$randnum. = substr ($str, $start, 1);
}
$this->randnum = $randnum;
$_session[an] = $this->randnum;
}
Get Verification code Picture Y axis
function get_y () {
if ($this->ext_rand_y) $this->y = rand (5, $this-&GT;IM_HEIGHT/5);
else $this->y = $this-&GT;IM_HEIGHT/4;
}

1 2

http://www.bkjia.com/PHPjc/444817.html www.bkjia.com true http://www.bkjia.com/PHPjc/444817.html techarticle development of the application of the verification code is not necessary, we often touch on the machine registration, then there is a verification code can effectively prevent such behavior, let's look at the I offer this ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.