Esempio n. 1
0
 static function GBVerify($length = 4, $type = 'png', $width = 180, $height = 50, $fontface = 'simhei.ttf', $verifyName = 'verify')
 {
     require_once APP_ROOT_PATH . "system/utils/es_string.php";
     $code = es_string::rand_string($length, 4);
     $width = $length * 45 > $width ? $length * 45 : $width;
     es_session::set($verifyName, md5($code));
     $im = imagecreatetruecolor($width, $height);
     $borderColor = imagecolorallocate($im, 100, 100, 100);
     //边框色
     $bkcolor = imagecolorallocate($im, 250, 250, 250);
     imagefill($im, 0, 0, $bkcolor);
     @imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     // 干扰
     for ($i = 0; $i < 15; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor);
     }
     for ($i = 0; $i < 255; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $fontcolor);
     }
     if (!is_file($fontface)) {
         $fontface = dirname(__FILE__) . "/" . $fontface;
     }
     for ($i = 0; $i < $length; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 120), mt_rand(0, 120), mt_rand(0, 120));
         //这样保证随机出来的颜色较深。
         $codex = msubstr($code, $i, 1);
         imagettftext($im, mt_rand(16, 20), mt_rand(-60, 60), 40 * $i + 20, mt_rand(30, 35), $fontcolor, $fontface, $codex);
     }
     es_image::output($im, $type);
 }
Esempio n. 2
0
function LOGIN_DES_KEY()
{
    if (!es_session::is_set("DES_KEY")) {
        require_once APP_ROOT_PATH . "system/utils/es_string.php";
        es_session::set("DES_KEY", es_string::rand_string(50));
    }
    return es_session::get("DES_KEY");
}
 /**
 +----------------------------------------------------------
 *  带格式生成随机字符 支持批量生成
 *  但可能存在重复
 +----------------------------------------------------------
 * @param es_string $format 字符格式
 *     # 表示数字 * 表示字母和数字 $ 表示字母
 * @param integer $number 生成数量
 +----------------------------------------------------------
 * @return es_string | array
 +----------------------------------------------------------
 */
 public static function build_format_rand($format, $number = 1)
 {
     $str = array();
     $length = strlen($format);
     for ($j = 0; $j < $number; $j++) {
         $strtemp = '';
         for ($i = 0; $i < $length; $i++) {
             $char = substr($format, $i, 1);
             switch ($char) {
                 case "*":
                     //字母和数字混合
                     $strtemp .= es_string::rand_string(1);
                     break;
                 case "#":
                     //数字
                     $strtemp .= es_string::rand_string(1, 1);
                     break;
                 case "\$":
                     //大写字母
                     $strtemp .= es_string::rand_string(1, 2);
                     break;
                 default:
                     //其他格式均不转换
                     $strtemp .= $char;
                     break;
             }
         }
         $str[] = $strtemp;
     }
     return $number == 1 ? $strtemp : $str;
 }