首页 > 语言 > PHP > 正文

php 验证码生成程序,可自动判断php gd库

2024-09-04 11:44:25
字体:大 中 小
来源:转载
供稿:网友
  1. function ShowKey() 
  2. { 
  3. $key=strtolower(domake_password(4)); 
  4. $set=esetcookie("checkkey",$key); 
  5.  //是否支持gd库 
  6. if (function_exists("imagejpeg")) { 
  7.    header ("Content-type: image/jpeg"); 
  8.    $img=imagecreate(69,20); 
  9.    $black=imagecolorallocate($img,255,255,255); 
  10.    $gray=imagecolorallocate($img,102,102,102); 
  11.    imagefill($img,0,0,$gray); 
  12.    imagestring($img,3,14,3,$key,$black); 
  13.    imagejpeg($img); 
  14.    imagedestroy($img); 
  15. } 
  16. elseif (function_exists("imagegif")) { 
  17.    header ("Content-type: image/gif"); 
  18.    $img=imagecreate(69,20); 
  19.    $black=imagecolorallocate($img,255,255,255); 
  20.    $gray=imagecolorallocate($img,102,102,102); 
  21.    imagefill($img,0,0,$gray); 
  22.    imagestring($img,3,14,3,$key,$black); 
  23.    imagegif($img); 
  24.    imagedestroy($img); 
  25. } 
  26. elseif (function_exists("imagepng")) { 
  27.  header ("Content-type: image/png"); 
  28.    $img=imagecreate(69,20); 
  29.    $black=imagecolorallocate($img,255,255,255); 
  30.    $gray=imagecolorallocate($img,102,102,102); 
  31.    imagefill($img,0,0,$gray); 
  32.    imagestring($img,3,14,3,$key,$black); 
  33.    imagepng($img); 
  34.    imagedestroy($img); 
  35. } 
  36. elseif (function_exists("imagewbmp")) { 
  37.  header ("Content-type: image/vnd.wap.wbmp"); 
  38.    $img=imagecreate(69,20); 
  39.    $black=imagecolorallocate($img,255,255,255); 
  40.    $gray=imagecolorallocate($img,102,102,102); 
  41.    imagefill($img,0,0,$gray); 
  42.    imagestring($img,3,14,3,$key,$black); 
  43.    imagewbmp($img); 
  44.    imagedestroy($img); 
  45. } 
  46. else { 
  47.  $set=esetcookie("checkkey","ebak"); 
  48.  @include("class/functions.php"); 
  49.  echo ReadFiletext("images/ebak.jpg"); 
  50. } 
  51. }//开源代码Vevb.com 
  52. ShowKey(); 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表