/gamecrawler/wp/youxisoso/verify.php
PHP | 159 lines | 105 code | 15 blank | 39 comment | 16 complexity | f7470169ab46eb77c790baef80787968 MD5 | raw file
- <?php
- /**
- Template Name:shengchengyz
- */
- class YL_Security_Secoder {
- //????session???
- public static $seKey = 'verify_py'; //??????
- public static $expire = 3000; // ????????s?
- //??????????01IO???????
- public static $codeSet = '3456789ABCDEFGHJKLMNPQRTUVWXY';
- public static $fontSize = 26; // ???????(px)
- public static $useCurve = true; // ???????
- public static $useNoise = true; // ??????
- public static $imageH = 0; // ??????
- public static $imageL = 0; // ??????
- public static $length = 4; // ?????
- public static $bg = array(243, 251, 254); // ??
-
- protected static $_image = null; // ???????
- protected static $_color = null; // ???????
-
- /**
- * ???????????????session?
- */
- public static function entry() {
- // ???(px)
- self::$imageL || self::$imageL = self::$length * self::$fontSize * 1.5 + self::$fontSize*1.5;
- // ???(px)
- self::$imageH || self::$imageH = self::$fontSize * 2;
- // ???? self::$imageL x self::$imageH ???
- self::$_image = imagecreate(self::$imageL, self::$imageH);
- // ????
- imagecolorallocate(self::$_image, self::$bg[0], self::$bg[1], self::$bg[2]);
- // ?????????
- self::$_color = imagecolorallocate(self::$_image, mt_rand(1,120), mt_rand(1,120), mt_rand(1,120));
- // ?????????????????????
- $ttf = dirname(__FILE__) . '/ttfs/t' . mt_rand(1, 10) . '.ttf';
-
- if (self::$useNoise) {
- // ???
- self::_writeNoise();
- }
- if (self::$useCurve) {
- // ????
- self::_writeCurve();
- }
-
- // ????
- $code = array(); // ???
- $codeNX = 0; // ????N???????
- if(empty($code) == true){
- for ($i = 0; $i<self::$length; $i++) {
- $code[$i] = self::$codeSet[mt_rand(0, 28)];
- $codeNX += mt_rand(self::$fontSize*1.2, self::$fontSize*1.6);
- // ????????
- imagettftext(self::$_image, self::$fontSize, mt_rand(-40, 70), $codeNX, self::$fontSize*1.5, self::$_color, $ttf, $code[$i]);
- }
- }
-
-
- // ?????
- isset($_SESSION) || session_start();
- $_SESSION[self::$seKey]['code'] = join('', $code); // ???????session, ????????
- $_SESSION[self::$seKey]['time'] = time(); // ???????
-
- header('Pragma: no-cache');
- header("content-type: image/JPEG; charset=utf-8");
-
- // ????
- imageJPEG(self::$_image);
- imagedestroy(self::$_image);
- }
-
- /**
- * ?????????????????????????(????????????)
- * ?????????y=Asin(?x+?)+b
- * ?????????????
- * A?????????????????
- * b??????Y???????????????????
- * ???????X??????????????????
- * ????????????T=2?/????
- */
- protected static function _writeCurve() {
- $A = mt_rand(1, self::$imageH/2); // ??
- $b = mt_rand(-self::$imageH/4, self::$imageH/4); // Y??????
- $f = mt_rand(-self::$imageH/4, self::$imageH/4); // X??????
- $T = mt_rand(self::$imageH*1.5, self::$imageL*2); // ??
- $w = (2* M_PI)/$T;
-
- $px1 = 0; // ?????????
- $px2 = mt_rand(self::$imageL/2, self::$imageL * 0.667); // ?????????
- for ($px=$px1; $px<=$px2; $px=$px+ 0.9) {
- if ($w!=0) {
- $py = $A * sin($w*$px + $f)+ $b + self::$imageH/2; // y = Asin(?x+?) + b
- $i = (int) ((self::$fontSize - 6)/4);
- while ($i > 0) {
- imagesetpixel(self::$_image, $px + $i, $py + $i, self::$_color);
- //???????imagettftext?imagestring??????
- $i--;
- }
- }
- }
-
- $A = mt_rand(1, self::$imageH/2); // ??
- $f = mt_rand(-self::$imageH/4, self::$imageH/4); // X??????
- $T = mt_rand(self::$imageH*1.5, self::$imageL*2); // ??
- $w = (2* M_PI)/$T;
- $b = $py - $A * sin($w*$px + $f) - self::$imageH/2;
- $px1 = $px2;
- $px2 = self::$imageL;
- for ($px=$px1; $px<=$px2; $px=$px+ 0.9) {
- if ($w!=0) {
- $py = $A * sin($w*$px + $f)+ $b + self::$imageH/2; // y = Asin(?x+?) + b
- $i = (int) ((self::$fontSize - 8)/4);
- while ($i > 0) {
- imagesetpixel(self::$_image, $px + $i, $py + $i, self::$_color);
- //??(while)???????imagettftext?imagestring?????????
- //????while?????????
- $i--;
- }
- }
- }
- }
-
- /**
- * ???
- * ???????????????
- */
- protected static function _writeNoise() {
- for($i = 0; $i < 10; $i++){
- //????
- $noiseColor = imagecolorallocate(
- self::$_image,
- mt_rand(150,225),
- mt_rand(150,225),
- mt_rand(150,225)
- );
- for($j = 0; $j < 5; $j++) {
- // ???
- imagestring(
- self::$_image,
- 5,
- mt_rand(-10, self::$imageL),
- mt_rand(-10, self::$imageH),
- self::$codeSet[mt_rand(0, 28)], // ?????????????
- $noiseColor
- );
- }
- }
- }
- }
-
-
- //??????????? ??????
- YL_Security_Secoder::$useNoise = true; //??????
- YL_Security_Secoder::$useCurve = true; //????????
- YL_Security_Secoder::entry();
-
- ?>