Home >Backend Development >PHP Tutorial >PHP method to generate clickable refresh verification code and simple example

PHP method to generate clickable refresh verification code and simple example

墨辰丷
墨辰丷Original
2018-06-02 11:27:141813browse

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>

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);
?>

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!

Statement:
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