Home > Backend Development > PHP Tutorial > Two PHP codes for generating graphic verification codes_PHP tutorial

Two PHP codes for generating graphic verification codes_PHP tutorial

WBOY
Release: 2016-07-13 10:46:09
Original
778 people have browsed it

Verification codes are often used in PHP. Below we provide you with some PHP verification code generation classes and programs. You can just copy them and use them directly. See the code below.

Verification codes are often used in PHP tutorials. Below we provide you with some PHP verification code generation classes and programs. You can just copy them and use them directly. See the code below.

session_start();
Header("Content-type: image/gif");
class SecurityCode
{
private $codes = '';
function __construct()
{
$code = '0-1-2-3-4-5-6-7-8-9-A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z';
$codeArray = explode('-',$code);
shuffle($codeArray);
$this->codes = implode('',array_slice($codeArray,0,4));
}
public function CreateImg()
{
$_SESSION['check_pic'] = $this->codes;
$img = imagecreate(70,25);
imagecolorallocate($img,222,222,222);
$testcolor1 = imagecolorallocate($img,255,0,0);
$testcolor2 = imagecolorallocate($img,51,51,51);
$testcolor3 = imagecolorallocate($img,0,0,255);
$testcolor4 = imagecolorallocate($img,255,0,255);
for ($i = 0; $i < 4; $i++)
{
imagestring($img,rand(5,6),8 + $i * 15,rand(2,8),$this->codes[$i],rand(1,4));
}
imagegif($img);
}
}
$code = new SecurityCode();
$code->CreateImg();
$code = NULL;
?>

Code 2

session_start();
for($i=0; $i<4; $i++){
$rand.= dechex(rand(1,15));
}
$_SESSION[check_pic]=$rand;
//echo $_SESSION[check_pic];
//Set image size">Image size
$im = imagecreatetruecolor(100,30);
// Set color
$bg=imagecolorallocate($im,0,0,0);
$te=imagecolorallocate($im,255,255,255);
//Write the string in the upper left corner of the image
imagestring($im,rand(5,6),rand(25,30),5,$rand,$te);
// Output image
header("Content-type:image/jpeg");
imagejpeg($im);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632979.htmlTechArticleVerification codes are often used in PHP. Below we provide you with some PHP verification code generation classes. With the program, you can just copy it and use it directly. See the code below. Verify...
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