//驗證碼
public function verifAction($num=3, $interference=true){
$image = imagecreate(100, 30); // 創(chuàng)建畫布
$bgcolor = imagecolorallocate($image, 255, 255, 255);//畫布背景顏色
imagefill($image,0,0,$bgcolor);//填充背景 輸出$num位驗證碼
$capatch='';
for($i=0;$i<$num;$i++){
$fontsize=14;//字體大小
$fontcolor=imagecolorallocate($image,rand(0,120),rand(0,120),rand(0,120));//字體顏色
$date='QWERTYUPASDGHJKZXCVBNMqwertyupasdfghjkzxcvbnm';
$fontcontent=substr($date,rand(0,strlen($date)-1),1);
$capatch.=$fontcontent;
$x=($i*100/$num)+rand(5,10);
$y=rand(5,10); //生成驗證碼
$_SESSION['capatch']=strtolower($capatch);
file_put_contents('a.txt', $_SESSION['capatch']);
imagestring($image,$fontsize,$x,$y,$fontcontent,$fontcolor);
}
//干擾點
if($interference == true){
for($i=0;$i<100;$i++){
$pointcolor=imagecolorallocate($image,rand(50,200),rand(50,200),rand(50,200));
imagesetpixel($image,rand(1,99),rand(1,29),$pointcolor);}//干擾線
for($i=0;$i<2;$i++){
$linecolor=imagecolorallocate($image,rand(100,200),rand(100,200),rand(100,200));
imageline($image,rand(1,99),rand(1,29),rand(1,99),rand(1,29),$linecolor);
}
}
$_SESSION['authcode']=$capatch;
header('content-type:image/png');
imagepng($image); // 輸出圖片
imagedestroy($image);//銷毀圖片
}
這段代碼在框架之外生成驗證碼是正常的,但是一旦放到代碼里面就不正常了。我用url直達這個函數(shù),得到的永遠是一片沒有驗證碼的黑色背景?請教各位大神,問題可能出在哪了?我用的是zend-framework框架.
-------------------分割線---------
public function verifAction(){
header("Content-type:image/png");
$a = imagecreate(100,100);
imagecolorallocate($a,255,0,255);
imagepng($a);
imagedestroy($a);
exit();
}
我剛剛再試發(fā)現(xiàn),只創(chuàng)建一塊畫面,畫布也輸不出來。這是哪里的問題?換了個瀏覽器是這樣的。
3 回答

波斯汪
TA貢獻1811條經(jīng)驗 獲得超4個贊
框架里a.txt有沒打印出什么東西,如果沒有,或許是跟session文件夾權(quán)限有關(guān)(如果是以文件形式存儲的話),將框架里存儲session的文件夾權(quán)限變?yōu)?77試試。
- 3 回答
- 0 關(guān)注
- 963 瀏覽
添加回答
舉報
0/150
提交
取消