PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/gamecrawler/wp/youxisoso/verify.php

http://collectgame.googlecode.com/
PHP | 159 lines | 105 code | 15 blank | 39 comment | 16 complexity | f7470169ab46eb77c790baef80787968 MD5 | raw file
  1. <?php
  2. /**
  3. Template Name:shengchengyz
  4. */
  5. class YL_Security_Secoder {
  6. //????session???
  7. public static $seKey = 'verify_py'; //??????
  8. public static $expire = 3000; // ????????s?
  9. //??????????01IO???????
  10. public static $codeSet = '3456789ABCDEFGHJKLMNPQRTUVWXY';
  11. public static $fontSize = 26; // ???????(px)
  12. public static $useCurve = true; // ???????
  13. public static $useNoise = true; // ??????
  14. public static $imageH = 0; // ??????
  15. public static $imageL = 0; // ??????
  16. public static $length = 4; // ?????
  17. public static $bg = array(243, 251, 254); // ??
  18. protected static $_image = null; // ???????
  19. protected static $_color = null; // ???????
  20. /**
  21. * ???????????????session?
  22. */
  23. public static function entry() {
  24. // ???(px)
  25. self::$imageL || self::$imageL = self::$length * self::$fontSize * 1.5 + self::$fontSize*1.5;
  26. // ???(px)
  27. self::$imageH || self::$imageH = self::$fontSize * 2;
  28. // ???? self::$imageL x self::$imageH ???
  29. self::$_image = imagecreate(self::$imageL, self::$imageH);
  30. // ????
  31. imagecolorallocate(self::$_image, self::$bg[0], self::$bg[1], self::$bg[2]);
  32. // ?????????
  33. self::$_color = imagecolorallocate(self::$_image, mt_rand(1,120), mt_rand(1,120), mt_rand(1,120));
  34. // ?????????????????????
  35. $ttf = dirname(__FILE__) . '/ttfs/t' . mt_rand(1, 10) . '.ttf';
  36. if (self::$useNoise) {
  37. // ???
  38. self::_writeNoise();
  39. }
  40. if (self::$useCurve) {
  41. // ????
  42. self::_writeCurve();
  43. }
  44. // ????
  45. $code = array(); // ???
  46. $codeNX = 0; // ????N???????
  47. if(empty($code) == true){
  48. for ($i = 0; $i<self::$length; $i++) {
  49. $code[$i] = self::$codeSet[mt_rand(0, 28)];
  50. $codeNX += mt_rand(self::$fontSize*1.2, self::$fontSize*1.6);
  51. // ????????
  52. imagettftext(self::$_image, self::$fontSize, mt_rand(-40, 70), $codeNX, self::$fontSize*1.5, self::$_color, $ttf, $code[$i]);
  53. }
  54. }
  55. // ?????
  56. isset($_SESSION) || session_start();
  57. $_SESSION[self::$seKey]['code'] = join('', $code); // ???????session, ????????
  58. $_SESSION[self::$seKey]['time'] = time(); // ???????
  59. header('Pragma: no-cache');
  60. header("content-type: image/JPEG; charset=utf-8");
  61. // ????
  62. imageJPEG(self::$_image);
  63. imagedestroy(self::$_image);
  64. }
  65. /**
  66. * ?????????????????????????(????????????)
  67. * ?????????y=Asin(?x+?)+b
  68. * ?????????????
  69. * A?????????????????
  70. * b??????Y???????????????????
  71. * ???????X??????????????????
  72. * ????????????T=2?/????
  73. */
  74. protected static function _writeCurve() {
  75. $A = mt_rand(1, self::$imageH/2); // ??
  76. $b = mt_rand(-self::$imageH/4, self::$imageH/4); // Y??????
  77. $f = mt_rand(-self::$imageH/4, self::$imageH/4); // X??????
  78. $T = mt_rand(self::$imageH*1.5, self::$imageL*2); // ??
  79. $w = (2* M_PI)/$T;
  80. $px1 = 0; // ?????????
  81. $px2 = mt_rand(self::$imageL/2, self::$imageL * 0.667); // ?????????
  82. for ($px=$px1; $px<=$px2; $px=$px+ 0.9) {
  83. if ($w!=0) {
  84. $py = $A * sin($w*$px + $f)+ $b + self::$imageH/2; // y = Asin(?x+?) + b
  85. $i = (int) ((self::$fontSize - 6)/4);
  86. while ($i > 0) {
  87. imagesetpixel(self::$_image, $px + $i, $py + $i, self::$_color);
  88. //???????imagettftext?imagestring??????
  89. $i--;
  90. }
  91. }
  92. }
  93. $A = mt_rand(1, self::$imageH/2); // ??
  94. $f = mt_rand(-self::$imageH/4, self::$imageH/4); // X??????
  95. $T = mt_rand(self::$imageH*1.5, self::$imageL*2); // ??
  96. $w = (2* M_PI)/$T;
  97. $b = $py - $A * sin($w*$px + $f) - self::$imageH/2;
  98. $px1 = $px2;
  99. $px2 = self::$imageL;
  100. for ($px=$px1; $px<=$px2; $px=$px+ 0.9) {
  101. if ($w!=0) {
  102. $py = $A * sin($w*$px + $f)+ $b + self::$imageH/2; // y = Asin(?x+?) + b
  103. $i = (int) ((self::$fontSize - 8)/4);
  104. while ($i > 0) {
  105. imagesetpixel(self::$_image, $px + $i, $py + $i, self::$_color);
  106. //??(while)???????imagettftext?imagestring?????????
  107. //????while?????????
  108. $i--;
  109. }
  110. }
  111. }
  112. }
  113. /**
  114. * ???
  115. * ???????????????
  116. */
  117. protected static function _writeNoise() {
  118. for($i = 0; $i < 10; $i++){
  119. //????
  120. $noiseColor = imagecolorallocate(
  121. self::$_image,
  122. mt_rand(150,225),
  123. mt_rand(150,225),
  124. mt_rand(150,225)
  125. );
  126. for($j = 0; $j < 5; $j++) {
  127. // ???
  128. imagestring(
  129. self::$_image,
  130. 5,
  131. mt_rand(-10, self::$imageL),
  132. mt_rand(-10, self::$imageH),
  133. self::$codeSet[mt_rand(0, 28)], // ?????????????
  134. $noiseColor
  135. );
  136. }
  137. }
  138. }
  139. }
  140. //??????????? ??????
  141. YL_Security_Secoder::$useNoise = true; //??????
  142. YL_Security_Secoder::$useCurve = true; //????????
  143. YL_Security_Secoder::entry();
  144. ?>