按照老师的步骤还是显示不了验证码!
按照老师的步骤还是显示不了验证码!还有老师哪些login、main、index、的PHP都是要自己打上?那些能用静态网站编辑吗?
按照老师的步骤还是显示不了验证码!还有老师哪些login、main、index、的PHP都是要自己打上?那些能用静态网站编辑吗?
2016-02-18
<?php
//通过GD库做验证码
//引用字符串类 得到随机字符串
require_once 'string.func.php';
function verifyimage($type, $length, $line, $pixel, $width, $height) {
$chars = buildRandomString ( $type, $length );
$_SESSION ["verify1"] = $chars;
//验证码图片的宽高
//创建画布
$image = imagecreatetruecolor ( $width, $height );
$white = imagecolorallocate ( $image, 255, 255, 255 );
//填充矩形画布
imagefilledrectangle ( $image, 1, 1, $width - 2, $height - 2, $white );
//输出字符 每个字的颜色不一样怎么办?
//由于字体的原因找成有的时候没有数字,请注意
$fontfiles = array ("batang.ttc", "calibri.ttf" );
for($j = 0; $j < $length; $j ++) {
$size = mt_rand ( 14, 18 );
$angle = mt_rand ( - 15, 15 );
$x = 5 + $j * $size;
$y = mt_rand ( 20, 26 );
$color = imagecolorallocate ( $image, mt_rand ( 50, 90 ), mt_rand ( 80, 200 ), mt_rand ( 90, 180 ) );
$fontfile = "../font/" . $fontfiles [mt_rand ( 0, count ( $fontfiles ) - 1 )];
$text = substr ( $chars, $j, 1 );
imagettftext ( $image, $size, $angle, $x, $y, $color, $fontfile, $text );
}
//加干扰点
if ($pixel) {
$color = imagecolorallocate ( $image, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
for($i = 0; $i < $pixel; $i ++) {
imagesetpixel ( $image, mt_rand ( 0, $width ), mt_rand ( 0, $height ), $color );
}
}
//加干扰线
if ($line) {
for($i = 0; $i < $line; $i ++) {
$color = imagecolorallocate ( $image, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
imageline ( $image, mt_rand ( 0, $width ), mt_rand ( 0, $height ), mt_rand ( 0, $width ), mt_rand ( 0, $height ), $color );
}
}
//声明输出图片的格式
@header ( "Content-Type:image/png" );
//输出图片
imagepng ( $image );
//销毁图片资源
imagedestroy ( $image );
}
php文件都是编辑工具自动生成的
<?php
//通过GD库做验证码
//引用字符串类 得到随机字符串
require_once 'string.func.php';
function verifyimage($type, $length, $line, $pixel, $width, $height) {
$chars = buildRandomString ( $type, $length );
$_SESSION ["verify1"] = $chars;
//验证码图片的宽高
//创建画布
$image = imagecreatetruecolor ( $width, $height );
$white = imagecolorallocate ( $image, 255, 255, 255 );
//填充矩形画布
imagefilledrectangle ( $image, 1, 1, $width - 2, $height - 2, $white );
//输出字符 每个字的颜色不一样怎么办?
//由于字体的原因找成有的时候没有数字,请注意
$fontfiles = array ("batang.ttc", "calibri.ttf" );
for($j = 0; $j < $length; $j ++) {
$size = mt_rand ( 14, 18 );
$angle = mt_rand ( - 15, 15 );
$x = 5 + $j * $size;
$y = mt_rand ( 20, 26 );
$color = imagecolorallocate ( $image, mt_rand ( 50, 90 ), mt_rand ( 80, 200 ), mt_rand ( 90, 180 ) );
$fontfile = "../font/" . $fontfiles [mt_rand ( 0, count ( $fontfiles ) - 1 )];
$text = substr ( $chars, $j, 1 );
imagettftext ( $image, $size, $angle, $x, $y, $color, $fontfile, $text );
}
//加干扰点
if ($pixel) {
$color = imagecolorallocate ( $image, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
for($i = 0; $i < $pixel; $i ++) {
imagesetpixel ( $image, mt_rand ( 0, $width ), mt_rand ( 0, $height ), $color );
}
}
//加干扰线
if ($line) {
for($i = 0; $i < $line; $i ++) {
$color = imagecolorallocate ( $image, mt_rand ( 0, 255 ), mt_rand ( 0, 255 ), mt_rand ( 0, 255 ) );
imageline ( $image, mt_rand ( 0, $width ), mt_rand ( 0, $height ), mt_rand ( 0, $width ), mt_rand ( 0, $height ), $color );
}
}
//声明输出图片的格式
@header ( "Content-Type:image/png" );
//输出图片
imagepng ( $image );
//销毁图片资源
imagedestroy ( $image );
}
php文件都是编辑工具自动生成的
举报