PHP realizes that clicking on the verification code or not seeing it clearly will refresh the verification code

小云云
Release: 2023-03-19 16:54:02
Original
5885 people have browsed it

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 who need it can refer to it. I hope it can help everyone.

This is a page that uses the GD library to generate a verification code

test.PHP

<?php 
header(&#39;Content-Type:image/jpeg&#39;); 
 $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 = &#39;&#39;; 
 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); 
?>
Copy after login

This is a page that can be partially refreshed and verified after clicking on the verification code or seeing it clearly. Code

test2.php

<script type="text/javascript"> 
 function shuaxin() 
 { 
  document.getElementById(&#39;code&#39;).src = "test.php?"+Math.random(); 
 } 
</script> 
<input type="text"><br /> 
<img id="code" src="test.php" onclick="shuaxin()" /> 
<span onclick="shuaxin()">看不清?</span><br />
Copy after login

is shown below:

##Related recommendations:


php implementation code for real-time refresh when clicking on the verification code

The above is the detailed content of PHP realizes that clicking on the verification code or not seeing it clearly will refresh the verification code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!