Verification code picture cannot display PHP's in-Question verification code

Source: Internet
Author: User
Copy CodeThe code is as follows:


Class Code
{
var $width = 160; The width of the picture
var $hight = 40; Picture of the High
var $image;
var $red = 223; RGB color of the picture
var $green = 225; Red
var $blue = 227;//Green
var $pix = 227;//Blue
var $pixcolor; Noise 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 miscellaneous points
var $i = 0;
var $widthpx = 0;
var $highty = 0;
var $txtreg = 50;
var $txtgreen = 30;
function createimage ()//Create a picture and fill 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 CAPTCHA text
{
$this->txt = Array ("I", "Love", "You", "leaves", "on", "Hui", "Ming", "FA", "true", "the", "very", "want", "no", "know", "to", "for", "what", "what", "on", "Yes", "Forget", "no", "the "You", "also", "Xu", "Shang", "generation", "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; The resulting validation ID
}
function createstring ()//create CAPTCHA Picture
{
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 ()//Get Verification code picture
{
$this->createimage ();
$this->gettxt ();
$this->createpix ();
$this->createstring ();
}
}
?>
Session_Start ();
$text = new Code;
$text->createimage ();
$text->gettxt ();
$text->createpix ();
$text->createstring ();
?>

The above describes the verification code picture can not display the PHP code, including the verification code picture can not display aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    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.