噜噜网所用的验证码样式
| |
2008/10/28 bo-blog
是不是觉得bo的验证码白底黑字很单调啊,只要简单修改一下就可以啦。
现在公开目前噜噜网所用的验证码样式代码。
直接覆盖inc/securitycode.php即可!

  1. <?PHP
  2. /* -----------------------------------------------------
  3. Bo-Blog 2 : The Blog Reloaded.
  4. <<A Bluview Technology Product>>
  5. 禁止使用Windows记事本修改文件,由此造成的一切使用不正常恕不解答!
  6. PHP+MySQL blog system.
  7. Code: Bob Shen
  8. Offical site: http://www.bo-blog.com
  9. Copyright (c) Bob Shen 中国-上海
  10. In memory of my university life
  11. ------------------------------------------------------- */
  12.  
  13. //Security Code Image Generation
  14. //This part needs GD Library to be installed
  15. //Original Code: 噜噜网 http://luluw.cn
  16. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  17. require_once ("../data/config.php");
  18.  
  19. if ($db_defaultsessdir!=1) session_save_path("../{$db_tmpdir}");
  20. session_cache_limiter("private, must-revalidate");
  21. session_start();
  22. session_register('code');
  23. $_SESSION['code'] = "";
  24. $width = "40";//图片宽
  25. $height = "15";//图片高
  26. $len = "4";//生成几位验证码
  27. $bgcolor = "#ffffff";//背景色
  28. $noise = true;//生成杂点
  29. $noisenum = 10;//杂点数量
  30. $border = false;//边框
  31. $bordercolor = "#000000";
  32. $image = imageCreate($width, $height);
  33. $back = getcolor($bgcolor);
  34. imageFilledRectangle($image, 0, 0, $width, $height, $back);
  35. $size = $width/$len;
  36. if($size>$height) $size=$height;
  37. $left = ($width-$len*($size+$size/10))/$size;
  38.  
  39. $textall=range('A','Z');
  40. for ($i=0; $i<$len; $i++) {
  41. $tmptext=rand(0, 25);
  42. $randtext = $textall[$tmptext];
  43. $code .= $randtext;
  44. }
  45. $textColor = imageColorAllocate($image, 0, 0, 0);
  46. imagestring($image, $size, 0, 0, $code, $textColor);
  47.  
  48. if($noise == true) setnoise();
  49. $_SESSION['code'] = $code;
  50. $bordercolor = getcolor($bordercolor);
  51. if($border==true) imageRectangle($image, 0, 0, $width-1, $height-1, $bordercolor);
  52. header("Content-type: image/png");
  53. imagePng($image);
  54. imagedestroy($image);
  55. function getcolor($color)
  56. {
  57. global $image;
  58. $color = eregi_replace ("^#","",$color);
  59. $r = $color[0].$color[1];
  60. $r = hexdec ($r);
  61. $b = $color[2].$color[3];
  62. $b = hexdec ($b);
  63. $g = $color[4].$color[5];
  64. $g = hexdec ($g);
  65. $color = imagecolorallocate ($image, $r, $b, $g);
  66. return $color;
  67. }
  68. function setnoise()
  69. {
  70. global $image, $width, $height, $back, $noisenum;
  71. for ($i=0; $i<$noisenum; $i++){
  72. $randColor = imageColorAllocate($image, rand(0, 255), rand(0, 255), rand(0, 255));
  73. imageSetPixel($image, rand(0, $width), rand(0, $height), $randColor);
  74. }
  75. }
  76. ?>
10K
本文来源: 噜噜网 | 目前已有 35552 人围观此文,标签: ,

浮上来留个足迹吧,看帖不回会被鄙视de哦: