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