Image Verification code-php Tutorial

Source: Internet
Author: User
The image verification code is a simple code for displaying the verification code. the code is as follows.
For ($ I = 0; $ I <4; $ I ++)
{
$ R. = dechex (rand (1, 15 ));
}

$ Im = imagecreatetruecolor (100,30 );
$ Bg = imagecolorallocate ($ im, 0); // The background color when the first call is made.
$ Te = imagecolorallocate ($ im, 255,255,255 );
Imagestring ($ im, 5, 0, 0, $ r, $ te );

Header ("content-type: image/jpeg ");
Imagejpeg ($ im );

The image is not displayed. if you remove $ r. = dechex (rand (), the image is displayed with only one digit.

Error message: Undefined variable: r. It should be that the variable is undefined and how to write it correctly.


Reply to discussion (solution)

$ R = '';
For ($ I = 0; $ I <4; $ I ++)
{
$ R. = dechex (rand (1, 15 ));
}

Set $ r as an initial character so that it can be used as a character connection below.

Error message: Undefined variable: r. It should be that the variable is undefined and how to write it correctly.

---------------------------------
Then define the variables.

The dechex () function converts decimal to hexadecimal.

The return type is string type.

So

$ R = null; or $ r = '';


Yes.

In addition, because PHP variables are of a weak type, you can define them as $ r = 0;

Good luck

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.