This article mainly introduces the relevant information on how to use the GD library to create verification codes in PHP (clicking on the verification code or not seeing it clearly will refresh the verification code), friends in need can refer to it
This is the use The page where the GD library generates the verification code
test.PHP
<?php header('Content-Type:image/jpeg'); $img = imagecreatetruecolor(100, 40); $black = imagecolorallocate($img, 0x00, 0x00, 0x00); $green = imagecolorallocate($img, 0x00, 0xFF, 0x00); $white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF); imagefill($img,0,0,$white); //生成随机的验证码 $code = ''; for($i = 0; $i < 4; $i++) { $code .= rand(0, 9); } imagestring($img, 5, 10, 10, $code, $black); //加入噪点干扰 for($i=0;$i<50;$i++) { imagesetpixel($img, rand(0, 100) , rand(0, 100) , $black); imagesetpixel($img, rand(0, 100) , rand(0, 100) , $green); } //输出验证码 header("content-type: image/png"); imagepng($img); imagedestroy($img); ?>
This is the verification code that can be partially refreshed after clicking the verification code or seeing it clearly
test2.php
<script type="text/javascript"> function shuaxin() { document.getElementById('code').src = "test.php?"+Math.random(); } </script> <input type="text"><br /> <img id="code" src="test.php" onclick="shuaxin()" / alt="Detailed explanation of how to use the GD library in PHP to complete the verification code effect tutorial" > <span onclick="shuaxin()">看不清?</span><br />
As shown below:
The above is the detailed content of Detailed explanation of how to use the GD library in PHP to complete the verification code effect tutorial. For more information, please follow other related articles on the PHP Chinese website!