為什么顯示不了驗(yàn)證碼,屏幕都是黑色的。各位大神求指點(diǎn)
image.func.php
<?php
require_once ('string.func.php');
session_start();
//通過GD庫做驗(yàn)證碼
//創(chuàng)建畫布
$width=80;
$height=28;
$image=imagecreatetruecolor($width, $height);//創(chuàng)建畫布的長與寬
$white=imagecolorallocate($image, red, 255,255,255);//選擇白色畫筆
$black=imagecolorallocate($image, red, 0,0,0);//選擇白色畫筆
//用矩形填充畫布
imagefilledrectangle($image, 1, 1, $width-2, $height-2,$white);//矩形左上角(1,1)開始到矩形右下角($width-2,$width-2)畫一個(gè)矩形并填充
$type=1;
$length=4;
$chars=buildRandomString($type,$length);
$sess_name="verify";//設(shè)置的驗(yàn)證碼
$_SESSION [$sess_name] = $chars;
$fontfiles=array("simhei.ttf","simkai.ttf","simsun.ttc","wingding.ttf");//選擇字體
for ($i=0; $i <$length ; $i++) {?
$size=mt_rand(14,18);//隨機(jī)產(chǎn)生的大小
$angle=mt_rand(-15,15);//隨機(jī)產(chǎn)生的角度
$x=5+$i*$size;
$fontfile = "../fonts/" . $fontfiles [mt_rand ( 0, count ( $fontfiles ) - 1 )];//隨機(jī)取出一個(gè)字體
$y=mt_rand(20,26);
$color=imagecolorallocate($image,mt_rand(50,90),mt_rand(80,200),mt_rand(90,180));
$text=substr($chars,$i,1);//
imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text);
}
header ( "content-type:image/gif" );//告訴瀏覽器要顯示什么資源
imagegif($image);//顯示畫布
imagedestroy($image);//銷毀畫布
?>
string.func.php
<?php
//隨機(jī)提取驗(yàn)證碼
function buildRandomString($type,$length){
if ($type==1) {
$chars=join('',range(0, 9));//隨機(jī)數(shù)字
}else if ($type==2) {
$chars=join('',array_merge(range("a","z"),range("A", "Z")));//隨機(jī)小寫+大寫字母
}else if ($type==3) {
$chars=join('',array_merge(range("a","z"),range("A", "Z"),range(0, 9)));//混合字母
}
if ($length>strlen($chars)) {
exit("字符串長度不夠");//提取的字符串的長度不能夠大于本身字符串的長度
}
$chars=str_shuffle($chars);//隨機(jī)打亂字符串
return substr($chars,0,$length);//從0開始提取$length長度的字符串
}
?>
找不出原因,求指導(dǎo)
2017-10-18
我也是黑乎乎的
2017-07-23
請問是怎么解決的?
2017-06-20
在zend studio中可以運(yùn)行,谷歌我也用不了
2017-05-30
怎么解決的啊
2017-05-21
已解決