PHP method to generate clickable refresh verification code and simple example

墨辰丷
Release: 2023-03-29 14:06:01
Original
1652 people have browsed it

This article mainly introduces the verification code generated by PHP that can be clicked to refresh. It analyzes the implementation and call display method of PHP verification code in the form of simple examples. It involves the related skills of dynamically calling the verification code PHP file with js. Friends who need it can For reference,

is as follows:

html file:

<html>
 <head>
   <title>验证码</title>
 </head>
  <script type="text/javascript">
    function yanzheng(){
      var im=document.getElementsByTagName("img");
      im[0].src="gd.php?temp="+(new Date().getTime().toString(36));
    }
  </script>
 <body>
  <img src="gd.php"/><a href="#" onclick="yanzheng()">换一张</a>
 </body>
</html>
Copy after login

Verification code file gd.php:

<?php
$im=imagecreate(50,20);
$b=imagecolorallocate($im,0,0,0);
$w=imagecolorallocate($im,255,255,255);
$mask="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$text="";
for($i=1;$i<=4;$i++){
  $index=rand(0,61);
  $text.=$mask{$index};
}
imagestring($im,3,rand(10,20),rand(0,10),$text,$w);
header("Content-type:image/jpeg");
imagejpeg($im);
?>
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP method to implement sorting of a certain key in a two-dimensional array


PHP automatically identifies the mobile terminal currently in use

PHP custom function format json data instance

The above is the detailed content of PHP method to generate clickable refresh verification code and simple example. 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!