Custom Hero Survival 1.87 PHP High Customization Security Verification Code Code

WBOY
Release: 2016-07-29 08:47:16
Original
1287 people have browsed it

Copy the code The code is as follows:


public function captcha(){
$font_dir = $_SERVER ["DOCUMENT_ROOT"] . "your_ttf_file.ttf"; // Font library
$img_w = 58; // Set the image width
$img_h = 20; // Set the image height
$font_size = 11; // Font size
$angle_l = -10; // Left deflection
$angle_r = 10; // Right deflection Corner
$code_str = "ABCDEFGHJKLMNPQRSTUVWXYZ36";
$word_len = 4; // Number of verification code digits
$padding = 5; // Space between each two words
$margin = 2; // Left margin
$ base_line = 15; // Text baseline position
$base_line_offset = 2; // Baseline offset
$pixel_num = 3; // Base number of noise points
$pixel_color= 8; // Noise points only have $pixel_color colors The number of noise points is $pixel_num*$pixel_color
$noise_font_size = 1; // Noise font size
$sessi // Custom session key name
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Pragma: no-cache");
header("Cache-control: private");
header('Content-Type : image/png');
session_start();
$word = "";
$code_str_len = strlen($code_str) - 1;
for ($i = 0; $i < $word_len; $i++) {
$word.= $code_str[rand(0, $code_str_len)];
}
$_SESSION [$session_key] = strtolower($word);
$image = imagecreatetruecolor($img_w, $img_h);
imagefilledrectangle($ image, 0, 0, $img_w - 1, $img_h - 1, imagecolorallocate($image, mt_rand(235, 255), mt_rand(235, 255), mt_rand(235, 255)));
//Draw noise
for($i = 0; $i < $pixel_color; $i++){
$noise_color = imagecolorallocate( $image, mt_rand(150,225), mt_rand(150,225), mt_rand(150,225) );
for($j = 0; $j < $pixel_num; $j++) {
imagestring( $image, $noise_font_size, mt_rand(-10, $img_w), mt_rand(-10, $img_h), $code_str[mt_rand(0, $code_str_len) ], $noise_color );
}
}
//Draw text
for ($i = 0; $i < $word_len; ++$i) {
$color = imagecolorallocate($image, mt_rand(0, 100 ), mt_rand(20, 120), mt_rand(50, 150));
imagettftext($image, $font_size, mt_rand($angle_l, $angle_r), $margin, mt_rand($base_line-$base_line_offset, $base_line+$base_line_offset ), $color, $font, mb_substr($word, $i, 1, 'utf-8'));
$margin += (imagefontwidth($font_size) + $padding);
}
imagepng($image) ;
imagedestroy($image);
exit;
}

The above introduces the Custom Hero Survival 1.87 PHP highly customizable security verification code code, including the content of Custom Hero Survival 1.87. I hope it will be helpful to friends who are interested in PHP tutorials.

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