- session_start ();
- header ( 'Content-type: image/png' );
- //Create image
- $im = imagecreate($x=130,$y=45 );
- $bg = imagecolorallocate($im,rand(50,200),rand(0,155),rand(0,155)); //The first call to imagecolorallocate() will fill 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 in the c:windowsFonts folder, I put it in and authcode. php file, you can replace other font styles here
- //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;//Compare the user with the verification code entered by the user
- //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 Click
- for ($i=0;$i<250;$i++){
- imagesetpixel($im,rand(0,$x),rand(0,$y),$fontColor);
- }
- imagepng($ im);
- imagedestroy($im);
- ?>
Copy code
|