Php q & A verification code

Source: Internet
Author: User

Copy codeThe Code is as follows: <? Php
Class code
{
Var $ width = 160; // The Image width
Var $ hight = 40; // The Image Height
Var $ image;
Var $ red = 223; // The RGB color of the image
Var $ green= 225; // red
Var $ blue = 227; // green
Var $ pix = 227; // blue
Var $ pixcolor; // color;
Var $ pixred= 242; // red
Var $ pixgreen= 168; // green
Var $ pixblue = 162; // blue
Var $ txt = null; // Verification Code text
Var $ txtcode = null;
Var $ txtsub = null;
Var $ pixnum = 300; // Number of vertices
Var $ I = 0;
Var $ widthpx = 0;
Var $ highty = 0;
Var $ txreg = 50;
Var $ txtgreen = 30;
Function createimage () // create a graph and fill in the color
{
$ This-> image = imagecreate ($ this-> width, $ this-> hight );
$ This-> color = imagecolorallocate ($ this-> image, $ this-> red, $ this-> green, $ this-> blue );
Return imagefill ($ this-> image, 0, 0, $ this-> color );
}
Function createpix () // interference factor
{
For ($ this-> I = 1; $ this-> I <$ this-> pixnum; $ this-> I ++)
{
$ This-> widthpx = rand (0, $ this-> width );
$ This-> highty = rand (0, $ this-> hight );
$ This-> pixcolor = imagecolorallocate ($ this-> image, $ this-> pixred, $ this-> pixgreen, $ this-> pixblue );
Imagesetpixel ($ this-> image, $ this-> widthpx, $ this-> highty, $ this-> pixcolor );
}
}
Function gettxt () // create the verification code text
{
$ This-> txt = array ("I", "love", "you", "Ye", "just", "Hui", "Ming", "Fa ", "True", "yes", "very", "think", "no", "Zhi", "to", "yes", "what", "what ", "just", "yes", "forget", "no", "no", "you", "also", "Xu", "Shang", "", "owe", "money ");
For ($ this-> I = 0; $ this-> I <6; $ this-> I ++)
{
$ This-> sub = $ this-> txt [rand (0, 29)];
$ This-> txtcode. = $ this-> sub;
}
$ This-> txtcode = iconv ("GB2312", "UTF-8", $ this-> txtcode );
$ _ SESSION ["code"] = $ this-> txtcode; // generated verification ID
}
Function createstring () // create a verification code Image
{
Imagettftext ($ this-> image, 20, 5, 0, 40, $ this-> pixcolor, "C: \ WINDOWS \ Fonts \ simsun. ttc", $ this-> txtcode );
Header ("content-type: image/png ");
Return imagepng ($ this-> image );
Imagedestroy ($ this-> image );
}
Function getcodeimage () // obtain the verification code Image
{
$ This-> createimage ();
$ This-> gettxt ();
$ This-> createpix ();
$ This-> createstring ();
}
}
?>
<? Php
Session_start ();
$ Text = new code;
$ Text-> createimage ();
$ Text-> gettxt ();
$ Text-> createpix ();
$ Text-> createstring ();
?>

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.