欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php生成酷炫的四個字符驗證碼

 更新時間:2016年04月22日 09:48:11   作者:六月天空的芬芳  
可以生成隨機顏色、干擾線條元素、干擾點元素的php驗證碼,這篇文章主要介紹了php生成酷炫的四個字符驗證碼的編寫方法,感興趣的小伙伴們可以參考一下

本文實例為大家分享php生成驗證碼的實現(xiàn)代碼,供大家參考,具體內容如下

<?php
$im=imagecreate(200,100);//生成畫布
imagecolorallocate($im,0,0,0);//背景色
$white=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));//生成隨機顏色
for($i=0;$i<9;$i++)
{
 imageline($im,rand(0,200),rand(0,100),rand(0,200),rand(0,100),$white);//生成干擾線條元素
}
for($i=0;$i<150;$i++)
{
 imagesetpixel($im,rand(0,200),rand(0,100),$white);//生成干擾點元素
}
for($i=0,$str='';$i<4;$i++)//通過循環(huán)獲得四個字符
{
 switch(rand(1,3))
 {
  case'1':
  $ch=rand(0,9);
  break; 
  case'2':
  $ch=sprintf('%c',rand(97,122));
  break;
  case'3':
  $ch=sprintf('%c',rand(65,90));
  break;
 }
  $str.=$ch;

}
imagettftext($im,32,rand(0,15),55,70,$white,'c.ttc',$str);//在畫布上輸出字符串
header("Content-type:image/jpeg");
imagejpeg($im);
imagedestroy($im);
?>

以上就是本文的全部內容,希望對大家學習PHP程序設計有所幫助。

相關文章

最新評論