- Session_Start ();
- Header (' content-type:image/png ');
- Create a picture
- $im = Imagecreate ($x =130, $y = 45);
- $BG = Imagecolorallocate ($im, Rand (50,200), Rand (0,155), Rand (0,155)); The first call to Imagecolorallocate () fills the background color of the palette-based image
- $fontColor = Imagecolorallocate ($im, 255, 255, 255); Font Color
- $fontstyle = ' Rock.ttf '; Font style, this can be found under the C:\windows\Fonts\ folder, I put it in the same directory as the authcode.php file, here can replace the other font style
- Generate random characters
- for ($i = 0; $i < 4; $i + +) {
- $randAsciiNumArray = Array (rand (48,57), Rand (65,90));
- $randAsciiNum = $randAsciiNumArray [Rand (0, 1)];
- $RANDSTR = Chr ($randAsciiNum);
- Imagettftext ($im, 30,rand (0,20)-rand (0,25), 5+ $i *30,rand (30,35), $fontColor, $fontstyle, $RANDSTR);
- $authcode. = $RANDSTR;
- }
- $_session[' authcode ' = $randFourStr;//user and user input verification code comparison
- Interference Line
- for ($i =0; $i <8; $i + +) {
- $lineColor = Imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
- Imageline ($im, rand (0, $x), 0,rand (0, $x), $y, $lineColor);
- }
- Interference Point
- for ($i =0; $i <250; $i + +) {
- Imagesetpixel ($im, rand (0, $x), rand (0, $y), $fontColor);
- }
- Imagepng ($im);
- Imagedestroy ($im);
- ?>
Copy Code
|