當前位置: 首頁>>代碼示例>>PHP>>正文


PHP String::rand_string方法代碼示例

本文整理匯總了PHP中String::rand_string方法的典型用法代碼示例。如果您正苦於以下問題:PHP String::rand_string方法的具體用法?PHP String::rand_string怎麽用?PHP String::rand_string使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在String的用法示例。


在下文中一共展示了String::rand_string方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: buildEmailVerify

 protected function buildEmailVerify($length = 20, $mode = 5, $verifyName = 'emailVerify')
 {
     import('ORG.Util.String');
     $verify = String::rand_string($length, $mode);
     $_SESSION[$verifyName] = md5($verify);
     return $verify;
 }
開發者ID:yunsite,項目名稱:he-zhong,代碼行數:7,代碼來源:CommonAction.class.php

示例2: build_format_rand

 /**
 +----------------------------------------------------------
 *  帶格式生成隨機字符 支持批量生成
 *  但可能存在重複
 +----------------------------------------------------------
 * @param string $format 字符格式
 *     # 表示數字 * 表示字母和數字 $ 表示字母
 * @param integer $number 生成數量
 +----------------------------------------------------------
 * @return 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 .= String::rand_string(1);
                     break;
                 case "#":
                     //數字
                     $strtemp .= String::rand_string(1, 1);
                     break;
                 case "\$":
                     //大寫字母
                     $strtemp .= String::rand_string(1, 2);
                     break;
                 default:
                     //其他格式均不轉換
                     $strtemp .= $char;
                     break;
             }
         }
         $str[] = $strtemp;
     }
     return $number == 1 ? $strtemp : $str;
 }
開發者ID:bibyzhang,項目名稱:produce_cms,代碼行數:43,代碼來源:String.class.php

示例3: GBVerify

 static function GBVerify($length = 4, $type = 'png', $width = 180, $height = 50, $fontface = 'simhei.ttf', $verifyName = 'verify')
 {
     include_once LIB_PATH . '/Misc/String.class.php';
     $code = String::rand_string($length, 4);
     $width = $length * 45 > $width ? $length * 45 : $width;
     $_SESSION[$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 = String::msubstr($code, $i, 1);
         imagettftext($im, mt_rand(16, 20), mt_rand(-60, 60), 40 * $i + 20, mt_rand(30, 35), $fontcolor, $fontface, $codex);
     }
     Image::output($im, $type);
 }
開發者ID:xingskycn,項目名稱:simple-php,代碼行數:32,代碼來源:Image.class.php

示例4: password

/**
 * 對用戶的密碼進行加密
 *
 * @param $password
 * @param $encrypt //傳入加密串,在修改密碼時做認證
 * @return array/password
 */
function password($password, $encrypt = '')
{
    $pwd = array();
    $pwd['encrypt'] = $encrypt ? $encrypt : String::rand_string(6);
    $pwd['password'] = md5(md5(trim($password)) . $pwd['encrypt']);
    return $encrypt ? $pwd['password'] : $pwd;
}
開發者ID:hubs,項目名稱:yuncms,代碼行數:14,代碼來源:custom.php

示例5: buildImageVerify

 /**
 +----------------------------------------------------------
 * 生成圖像驗證碼
 +----------------------------------------------------------
 * @static
 * @access public
 +----------------------------------------------------------
 * @param string $length  位數
 * @param string $mode  類型
 * @param string $type 圖像格式
 * @param string $width  寬度
 * @param string $height  高度
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 */
 static function buildImageVerify($length = 4, $mode = 1, $type = 'png', $width = 48, $height = 22, $verifyName = 'verify')
 {
     import('@.ORG.String');
     $randval = String::rand_string($length, $mode);
     $_SESSION[$verifyName] = md5($randval);
     $width = $length * 10 + 10 > $width ? $length * 10 + 10 : $width;
     if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
         $im = @imagecreatetruecolor($width, $height);
     } else {
         $im = @imagecreate($width, $height);
     }
     $r = array(225, 255, 255, 223);
     $g = array(225, 236, 237, 255);
     $b = array(225, 236, 166, 125);
     $key = mt_rand(0, 3);
     $backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]);
     //背景色(隨機)
     $borderColor = imagecolorallocate($im, 100, 100, 100);
     //邊框色
     $pointColor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
     //點顏色
     @imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
     @imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
     // 幹擾
     for ($i = 0; $i < 10; $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 < 25; $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), $pointColor);
     }
     for ($i = 0; $i < $length; $i++) {
         imagestring($im, 5, $i * 10 + 5, mt_rand(1, 8), $randval[$i], $stringColor);
     }
     //        @imagestring($im, 5, 5, 3, $randval, $stringColor);
     Image::output($im, $type);
 }
開發者ID:yunsite,項目名稱:nuomituan,代碼行數:55,代碼來源:Image.class.php

示例6: sendAuditMsg

 /**
  * @Title: sendAuditMsg
  * @Description: todo(手機短信發送)
  * @param int $id 當前模型數據ID
  * @param string $m  控製器名稱
  * @param id $userid 後台用戶ID
  * @param unknown_type $systemtype
  * @author liminggang
  * @date 2013-7-12 下午4:41:45
  * @throws
  */
 public function sendAuditMsg($id = "", $m = "", $userid = "", $systemtype = 0)
 {
     $md = $m ? $m : $this->getActionName();
     //第一步、獲取需要發送的短信內容
     $content = $this->setProcessModelMesg($md, $id);
     //第二步、獲取係統自帶的內容,在判斷內容大小
     import('@.ORG.String');
     $code = String::rand_string(4, 1);
     //第三步、驗證回複驗證碼是否有重複
     $MessageVerifyDao = M('message_verify');
     $map = array();
     $map['code'] = $code;
     $map['isreply'] = 0;
     $count = $MessageVerifyDao->where($map)->count("*");
     while ($count > 0) {
         $code = String::rand_string(4, 1);
         $map = array();
         $map['code'] = $code;
         $map['isreply'] = 0;
         $count = $MessageVerifyDao->where($map)->count("*");
     }
     //第四步、根據後台用戶ID獲取用戶手機號碼(這裏必須獲取的是通過驗證的手機號碼)
     $UserDao = M('user');
     $map = array();
     $map['mobilestatus'] = 1;
     $map['id'] = $userid;
     $mobile = $UserDao->where($map)->field("mobile")->find();
     if (!$mobile) {
         $this->error("此用戶的手機未通過驗證!不能發送短信");
     }
     $data['code'] = $code;
     $data["tablename"] = $md;
     $data["tableid"] = $id;
     $data["replyuser"] = $userid;
     $data["replytel"] = $mobile['mobile'];
     $data["createtime"] = time();
     $re = $MessageVerifyDao->add($data);
     if ($re) {
         //限製發送內容長度在240個字符內,如果超出了則用...替代
         $content .= " 回複" . $code . "01+批複內容 批複; 回複" . $code . "00+批複內容 打回";
         $remsg = $this->SendTelmMsg($content, $data["replytel"], $systemtype);
         $msgstatus = intval(trim($remsg));
         if ($msgstatus != 1 && $msgstatus != 0) {
             $this->error("短信發送失敗" . $msgstatus);
         }
     } else {
         $this->error("操作失敗");
     }
     //$r="||15123132519#123456#1同意#2013-07-10 17:33:55#";
     //$this->success ( L('_SUCCESS_') );
 }
開發者ID:tmlsoft,項目名稱:main,代碼行數:62,代碼來源:CommonAction.class.php

示例7: formatContent

 private function formatContent($content, $data, $type)
 {
     switch ($type) {
         case 1:
         case 2:
         case 4:
         case 5:
             $content = str_replace('{rand}', $data['rand'], $this->_defaultHash[$type]);
             break;
         case 3:
             tsload(ADDON_PATH . 'brary/String.class.php');
             $rndstr = String::rand_string(5, 3);
             $pwd = $rndstr . $data['rand'];
             $content = str_replace('{pwd}', $pwd, $this->_defaultHash[$type]);
             $map['login'] = $data['communication'];
             $uname = model('User')->where($map)->getField('uname');
             $content = str_replace('{name}', $uname, $content);
             $setuser['login_salt'] = rand(10000, 99999);
             $setuser['password'] = md5(md5($pwd) . $setuser['login_salt']);
             model('User')->where($map)->save($setuser);
             break;
     }
     return $content;
 }
開發者ID:songhongyu,項目名稱:THINKSNS,代碼行數:24,代碼來源:CaptchaModel.class.php

示例8: C

     $database = C('database', 'default');
     $testdata = $_POST['testdata'];
     $selectapp = $_POST['selectapp'];
     include INS_PATH . "step/step_" . $step . ".tpl.php";
     break;
 case '6':
     // 安裝詳細過程
     $db_config = array('hostname' => $_POST['dbhost'], 'username' => $_POST['dbuser'], 'password' => $_POST['dbpw'], 'database' => $_POST['dbname'], 'prefix' => $_POST['prefix'], 'pconnect' => $_POST['pconnect'], 'charset' => $_POST['dbcharset']);
     \Leaps\Base\Config::modify('database', $db_config);
     // 寫入數據庫配置信息
     \Leaps\Base\Config::modify('cookie', array('prefix' => String::rand_string(5) . '_'));
     // Cookie前綴
     // 附件訪問路徑
     \Leaps\Base\Config::modify('attachment', array('upload_url' => $siteurl . 'data/attachment/'));
     \Leaps\Base\Config::modify('attachment', array('avatar_url' => $siteurl . 'data/avatar/'));
     $auth_key = String::rand_string(20);
     \Leaps\Base\Config::modify('config', array('auth_key' => $auth_key));
     $uuid = String::uuid(C('version', 'product') . '-');
     \Leaps\Base\Config::modify('version', array('uuid' => $uuid));
     \Leaps\Base\Config::modify('system', array('js_path' => $siteurl . 'statics/js/', 'css_path' => $siteurl . 'statics/css/', 'img_path' => $siteurl . 'statics/images/', 'app_path' => $siteurl, 'skin_path' => $siteurl . 'statics/skins/'));
     $selectapp = $_POST['selectapp'];
     $testdata = $_POST['testdata'];
     include INS_PATH . "step/step_" . $step . ".tpl.php";
     break;
 case '7':
     // 完成安裝
     //File::write ( DATA_PATH . 'install.lock', 'ok' );
     include INS_PATH . "step/step_" . $step . ".tpl.php";
     //Folder::rm(INS_PATH);//刪除安裝目錄
     break;
 case 'installapp':
開發者ID:hubs,項目名稱:yuncms,代碼行數:31,代碼來源:index.php

示例9: sendPasswordApi

 public function sendPasswordApi($tel)
 {
     //發送注冊短信
     $tel = t($tel);
     if (!$tel) {
         return false;
     }
     $data['Mobile'] = $tel;
     $data['Rand'] = rand(11111, 99999);
     $data['Type'] = 3;
     $data['Status'] = 0;
     $data['level'] = 0;
     $data['AddDate'] = date('Y-m-d H:i:s');
     tsload(ADDON_PATH . 'brary/String.class.php');
     $rndstr = String::rand_string(5, 3);
     $pwd = $rndstr . $data['Rand'];
     $data['smsContent'] = '親愛的用戶,您的當前密碼為:' . $pwd;
     $res = $this->add($data);
     $map['login'] = $tel;
     $setuser['login_salt'] = rand(10000, 99999);
     $setuser['password'] = md5(md5($pwd) . $setuser['login_salt']);
     $res = model('User')->where($map)->save($setuser);
     return $res;
 }
開發者ID:317703064,項目名稱:ssat,代碼行數:24,代碼來源:SmsModel.class.php

示例10: add

 /**
  * 添加會員
  */
 public function add()
 {
     header("Cache-control: private");
     if (isset($_POST['dosubmit'])) {
         $info = array();
         if ($this->api->check_username($_POST['info']['username']) != 1) {
             showmessage(L('member_exist'));
         }
         $info = $this->_checkuserinfo($_POST['info']);
         if (!Validate::is_password($info['password'])) {
             showmessage(L('password_format_incorrect'));
         }
         $info['encrypt'] = String::rand_string(6);
         $info['regip'] = IP;
         $info['overduedate'] = isset($info['overduedate']) && !empty($info['overduedate']) ? strtotime($info['overduedate']) : 0;
         unset($info['pwdconfirm']);
         $info['regdate'] = $info['lastdate'] = TIME;
         $userid = $this->api->add($info);
         if ($userid > 0) {
             showmessage(L('operation_success'), U('member/member/add'), '', 'add');
         } else {
             switch ($userid) {
                 case '-1':
                     showmessage(L('username_illegal'), HTTP_REFERER);
                     // 用戶名不合法
                     break;
                 case '-2':
                     showmessage(L('username_deny'), HTTP_REFERER);
                     // 用戶名包含不允許注冊的詞語
                     break;
                 case '-3':
                     showmessage(L('member_exist'), HTTP_REFERER);
                     // 用戶名已存在
                     break;
                 case '-4':
                     showmessage(L('email_illegal'), HTTP_REFERER);
                     // E-mail不合法
                     break;
                 case '-5':
                     showmessage(L('email_deny'), HTTP_REFERER);
                     // E-mail不允許注冊
                     break;
                 case '-6':
                     showmessage(L('email_already_exist'), HTTP_REFERER);
                     // 該Email已經被注冊
                     break;
                 case '-7':
                     showmessage(L('operation_failure'), HTTP_REFERER);
                     break;
             }
         }
     } else {
         $show_header = $show_scroll = true;
         // 會員組緩存
         $group_cache = S('member/grouplist');
         foreach ($group_cache as $_key => $_value) {
             $grouplist[$_key] = $_value['name'];
         }
         // 會員模型緩存
         $member_model_cache = S('common/member_model');
         foreach ($member_model_cache as $_key => $_value) {
             $modellist[$_key] = $_value['name'];
         }
         include $this->view('member_add');
     }
 }
開發者ID:hubs,項目名稱:yuncms,代碼行數:69,代碼來源:MemberController.php

示例11: public_forget_password

 /**
  * 找回密碼
  */
 public function public_forget_password()
 {
     if (isset($_POST['dosubmit'])) {
         $checkcode = isset($_POST['code']) && trim($_POST['code']) ? trim($_POST['code']) : showmessage(L('input_code'), HTTP_REFERER);
         if (!checkcode($checkcode)) {
             // 判斷驗證碼
             showmessage(L('code_error'), HTTP_REFERER);
         }
         $memberinfo = $this->db->getby_email($_POST['email']);
         if (!empty($memberinfo['email'])) {
             $email = $memberinfo['email'];
         } else {
             showmessage(L('email_error'), HTTP_REFERER);
         }
         $code = String::authcode($memberinfo['userid'] . "\t" . TIME, 'ENCODE', $this->auth_key);
         $url = SITE_URL . "index.php?app=member&controller=passport&action=public_forget_password&code={$code}";
         $message = $this->member_setting['forgetpassword'];
         $message = str_replace(array('{click}', '{url}'), array('<a href="' . $url . '">' . L('please_click') . '</a>', $url), $message);
         sendmail($email, L('forgetpassword'), $message);
         showmessage(L('operation_success'), 'index.php?app=member&controller=passport&action=login');
     } elseif (isset($_GET['code'])) {
         $hour = date('y-m-d h', TIME);
         $code = String::authcode($_GET['code'], 'DECODE', $this->auth_key);
         $code = explode("\t", $code);
         if (is_array($code) && is_numeric($code[0]) && date('y-m-d h', TIME) == date('y-m-d h', $code[1])) {
             $memberinfo = $this->db->getby_userid($code[0]);
             $password = String::rand_string(8);
             $updateinfo['password'] = password($password, $memberinfo['encrypt']);
             $this->db->where(array('userid' => $code[0]))->update($updateinfo);
             if (!is_null($this->api->uc) && !empty($memberinfo['ucenterid'])) {
                 $this->api->uc->uc_user_edit($memberinfo['username'], '', $password, '', 1);
             }
             showmessage(L('operation_success') . L('newpassword') . ':' . $password);
         } else {
             showmessage(L('operation_failure'), 'index.php?app=member&controller=passport&action=login');
         }
     } else {
         $siteinfo = S('common/common');
         include template('member', 'forget_password');
     }
 }
開發者ID:hubs,項目名稱:yuncms,代碼行數:44,代碼來源:PassportController.php

示例12: download

 public function download()
 {
     $a_k = trim($_GET['a_k']);
     $yun_auth_key = md5($this->auth_key . $_SERVER['HTTP_USER_AGENT']);
     $a_k = String::authcode($a_k, 'DECODE', $yun_auth_key);
     if (empty($a_k)) {
         showmessage(L('illegal_parameters'));
     }
     unset($i, $m, $f, $t, $ip);
     parse_str($a_k);
     if (isset($i)) {
         $downid = intval($i);
     }
     if (!isset($m)) {
         showmessage(L('illegal_parameters'));
     }
     if (!isset($modelid)) {
         showmessage(L('illegal_parameters'));
     }
     if (empty($f)) {
         showmessage(L('url_invalid'));
     }
     if (!$i || $m < 0) {
         showmessage(L('illegal_parameters'));
     }
     if (!isset($t)) {
         showmessage(L('illegal_parameters'));
     }
     if (!isset($ip)) {
         showmessage(L('illegal_parameters'));
     }
     $starttime = intval($t);
     if (preg_match('/(php|phtml|php3|php4|jsp|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\\.|$)/i', $f) || strpos($f, ":\\") !== FALSE || strpos($f, '..') !== FALSE) {
         showmessage(L('url_error'));
     }
     $fileurl = trim($f);
     if (!isset($downid) || empty($fileurl) || !preg_match("/[0-9]{10}/", $starttime) || !preg_match("/[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/", $ip) || $ip != IP) {
         showmessage(L('illegal_parameters'));
     }
     $endtime = TIME - $starttime;
     if ($endtime > 3600) {
         showmessage(L('url_invalid'));
     }
     if ($m) {
         $fileurl = trim($s) . trim($fileurl);
     }
     //遠程文件
     if (strpos($fileurl, ':/') && strpos($fileurl, C('attachment', 'upload_url')) === false) {
         header("Location: {$fileurl}");
     } else {
         if ($d == 0) {
             header("Location: " . $fileurl);
         } else {
             $fileurl = str_replace(array(C('attachment', 'upload_url'), '/'), array(C('attachment', 'upload_path'), DIRECTORY_SEPARATOR), $fileurl);
             $filename = basename($fileurl);
             //處理中文文件
             if (preg_match("/^([\\s\\S]*?)([�-�][@-�])([\\s\\S]*?)/", $fileurl)) {
                 $filename = str_replace(array("%5C", "%2F", "%3A"), array("\\", "/", ":"), urlencode($fileurl));
                 $filename = urldecode(basename($filename));
             }
             $ext = File::get_suffix($filename);
             $filename = date('Ymd_his') . String::rand_string(3) . '.' . $ext;
             File::down($fileurl, $filename);
         }
     }
 }
開發者ID:hubs,項目名稱:yuncms,代碼行數:66,代碼來源:DownController.php

示例13: creat_code

 /**
  * 生成隨機驗證碼。
  */
 public function creat_code()
 {
     $this->response = String::rand_string(4);
     Loader::session();
     $_SESSION['code'] = strtolower($this->response);
 }
開發者ID:hubs,項目名稱:yuncms,代碼行數:9,代碼來源:Captcha.php


注:本文中的String::rand_string方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。