PHP verification code Image cannot display solution

Source: Internet
Author: User
The PHP verification code image does not display the PHP verification code Image. it does not display a red cross. The code is as follows: image. phpPHPcode & lt ;? Phpsession_start (); if (isset ($ _ POST [& #39; submit & #39;]) {if (trim ($ _ POST [& quot; test & quot;]) $ _ SESSION [& PHP verification code Image not displayed
The PHP verification code image cannot be displayed, and a Red Cross is displayed. The code is as follows:



Image. php
PHP code
 
Session_start ();
If (isset ($ _ POST ['submit ']) {
If (trim ($ _ POST ["test"]) == _ SESSION ['validationcode']) {
Echo 'submitted successfully
';
} Else {
Echo 'verification code input error !!
';
}
}
?>


Image

Script
Function newgdcode (obj, url ){
// Enter a random parameter next to it. Otherwise, the image will not be refreshed under IE7 or Firefox.
Obj. src = url + '? Nowtime = '+ new Date (). getTime ();
}
Script









Imgcode. php
PHP code
  
  showImage();    $_SESSION['validationcode'] =$image->getCheckCode(); ?>



ValidationCode. php
PHP code
  
  Width = $ width; // specify $ this-> height = $ height for the width attribute of the member; // specify $ this-> codeNum = $ codeNum; // code $ this-> checkCode = $ this-> createCheckCode (); // function showImage () {// output the image $ this-> getCreateImage () to the browser by accessing this method (); // call an internal method to create a canvas and make it original $ this-> outputText (); // output a random string $ this-> setDisturbColor () to the image (); // set some interference pixels to the image $ this-> outputImage (); // generate the image in the corresponding format and output} function getCheckCod E () {// access this method to obtain the randomly created verification code string return $ this-> checkCode; // return the member attribute $ checkCode saved string} private function getCreateImage () {// used to create image resources and visualize the background $ this-> image = imageCreate ($ this-> width, $ this-> height ); $ back = imageColorAllocate ($ this-> image, 255,255,255); $ border = imageColorAllocate ($ this-> image, 0, 0, 0); imageRectangle ($ this-> image, 0, 0, $ this-> width-1, $ this-> height-1, $ border);} private function createCheckCode () {// Randomly generate a specified number of strings for ($ I = 0; $ I <$ this-> codeNum; $ I ++) {$ number = rand ); switch ($ number) {case 0: $ rand_number = rand (48,57); break; // number case 1: $ rand_number = rand (65,90); break; // case 2: $ rand_number = rand (97,122); break; // lowercase letter} $ ascii = sprintf ("% c", $ rand_number ); $ ascii_number = $ ascii_number. $ ascii;} return $ ascii_number;} private function setDisturbColor () {// sets the interference pixel and outputs 100 vertices of different colors to the image. ($ I = 0; $ I <= 100; $ I ++) {$ color = imagecolorallocate ($ this-> image, rand (0,255), rand (0,255 ), rand (0,255); imagesetpixel ($ this-> image, rand (1, $ this-> width-2), rand (1, $ this-> height-2 ), $ color) ;}} private function outputText () {// random color, random placement, random string output to the image for ($ I = 0; $ I <= $ this-> codeNum; $ I ++) {$ bg_color = imagecolorallocate ($ this-> image, rand (0,255), rand (0,128 ), rand (0,255); $ x = floor ($ this-> width/$ this-> c OdeNum) * $ I + 3; $ y = rand (0, $ this-> height-15); imagechar ($ this-> image, 5, $ x, $ y, $ this-> checkCode [$ I], $ bg_color) ;}} private function outputImage () {// automatically detects the image types supported by GD and outputs the image if (imagetypes () & IMG_GIF) {// Determine whether the function that generates the GIF image has a header ("Content-type: image/gif "); // Set the MIME type for sending header information to image/gif imagegif ($ this-> image); // output the image to the browser} elseif (imagetypes () & IMG_JPG) in GIF format) {// Determine whether the function for generating JPG images contains a header ("Content-type: Image/jpeg "); // Set the MIME type of the sent header to image/jpeg imagejpeg ($ this-> image," ", 0.5 ); // output the image in JPEN format to the browser} elseif (imagetypes () & IMG_PNG) {// Determine whether the function for generating the PNG image has a header ("Content-type: image/png "); // Set the MIME type for sending header information to image/png imagepng ($ this-> image ); // output the image in PNG format to the browser} elseif (imagetypes () & IMG_WBMP) {// Determine whether the function for generating the WBMP image has header ("Content-type: image/vnd. wap. wbmp "); // The sending header is image/wbmp imagewbmp ($ this-> image ); // WBMP format outputs the image to the browser} else {// if there is no supported Image type die ("PHP does not support Image creation! "); // No image is output. an error message is output and the program is exited.} function _ destruct () {// when the object ends, destroy the image resources and release the memory imagedestroy ($ this-> image); // call the method in the GD library to destroy the image resources}?>

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.