// Before running, your computer needs to be able to run the PHP environment. Below are some of my practices
// This is a running page
// Show.html --- name
--------------------------------
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> insert title here </title>
</Head>
<Body>
// an IMG tag used to display the verification code
<Span id = "change_code" style = "cursor: Pointer"> invisible </span> // click the key
// Extremely simple JSCode, It will be easier to use jquery
<SCRIPT type = "text/JavaScript">
Showval (); // run the verification code output once.
Document. getelementbyid ('change _ Code'). onclick = showval; // click the event to call
Function showval () {// Click Event
VaR numstr = "";
For (I = 0; I <4; I ++ ){
Num = math. Round (math. Random () * 10); // random 4-digit
Numstr + = num;
}
Document. getelementbyid ('code'). src = 'valcode. php? Num = '+ numstr; // import to SRC of IMG
}
</SCRIPT>
</Body>
</Html>
-----------------------------------------------------------------
// The above explanation is quite simple. The following is the main PHP code. It is the same as the previous article, but it has changed a little bit. Below is all the code
// The interpretation of the Code is the same as that of the previous chapter, so I didn't elaborate on it. I just explained it in part.
// Valcode. php // This is the name
-------------------------------------------------------------
<? PHP
Header ("Content-Type: image/PNG"); // header output.
$ Width = 80;
$ Height = 42;
$ Numimage = imagecreate ($ width, $ height );
Imagecolorallocate ($ numimage, 240,240,240 );
$ Num = $ _ Get ['num']; // ----------------then, the SRC of the last line in show.html contains a num, which can be obtained using the get method.
For ($ I = 0; $ I <strlen ($ num); $ I ++)
{
$ X = mt_rand (0, 10) + $ width * $ I/4;
$ Y = mt_rand (2, $ height/3 );
$ Color = imagecolorallocate ($ numimage, mt_rand (0,255), mt_rand (0,255), mt_rand (0,255 ));
Imagestring ($ numimage, 5, $ X, $ y, $ num {$ I}, $ color );
}
$ Color = imagecolorallocate ($ numimage, 100, 60,155 );
For ($ I = 0; I I <200; $ I ++ ){
Imagesetpixel ($ numimage, mt_rand (0, 80), mt_rand (0, 42), $ color );
}
Imagepng ($ numimage );
Imagedestroy ($ numimage );
?>
----------------------------------------------------------
Now you can try it.