<?php
error_reporting(E_ALL);
session_start();
define ("DIR_ROOT",dirname(__FILE__)."/lib/");
$data = array
(
2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','m','n','p',
'q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G',
'H','I','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z'
);
$keys = array_rand($data,4);
$code_str = $data[$keys[0]].$data[$keys[1]].$data[$keys[2]].$data[$keys[3]];
$_SESSION["code"] = $code_str;
$img_w
=
100;
//验证码图片的高度
$img_h
=
30;
//验证码图片的宽度
$font_size =
15;
//文字的大小
$font_path =
DIR_ROOT."jdst.ttf";
//加载字体的位置
$scale
= 5;
//文字放大倍数
$img
=
imagecreatetruecolor($img_w,$img_h);
//新建一个真彩色图像
$fontcolor =
imagecolorallocate($img,255,255,255); //生成的字体颜色
$background =
imagefilledrectangle($img,0,0,$img_w,$img_h,$fontcolor);//填充画布
//文字基准点横坐标
$base_point_x = $img_w/7;
//文字基准点纵坐标
$base_point_y = $img_h/3;
$color = imagecolorallocate($img, mt_rand(0, 100), mt_rand(20, 120), mt_rand(50, 150));
for ($i = 0; $i < 4; ++$i) {
$coords =
imagettftext($img, $font_size, 0, $base_point_x, 21,
$color,$font_path, mb_substr($code_str, $i, 1, 'utf-8'));
$base_point_x = $coords[2] + 10 ;
}
//头信息
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');
imagepng($img);
//以png格式输出图像
imagedestroy($img);
//销毁图像
?>
error_reporting(E_ALL);
session_start();
define ("DIR_ROOT",dirname(__FILE__)."/lib/");
$data = array
$keys = array_rand($data,4);
$code_str = $data[$keys[0]].$data[$keys[1]].$data[$keys[2]].$data[$keys[3]];
$_SESSION["code"] = $code_str;
$img_w
$img_h
$font_size
$font_path
$scale
$img
$fontcolor
$background
//文字基准点横坐标
$base_point_x = $img_w/7;
//文字基准点纵坐标
$base_point_y = $img_h/3;
$color = imagecolorallocate($img, mt_rand(0, 100), mt_rand(20, 120), mt_rand(50, 150));
for ($i = 0; $i < 4; ++$i) {
}
//头信息
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');
imagepng($img);
imagedestroy($img);
?>
3167

被折叠的 条评论
为什么被折叠?



