Example #1
0
$wordListLength = count($wordList);
//call getRandomWord once for each word requested by the user via the numWords variable
for ($i = 0; $i <= $numWords; $i++) {
    $words[$i] = $randomWord = getRandomWord($wordList, $wordListLength - 1);
}
//concatenate all of the random words together to make a single string
for ($i = 0; $i < sizeof($words) - 1; $i++) {
    $password .= $words[$i];
}
//include special characters if requested
for ($i = 0; $i < $numChars; $i++) {
    $password .= getRandomSymbol();
}
//include numbers if requested
for ($i = 0; $i < $numNums; $i++) {
    $password .= getRandomNum();
}
//call the setCapitalization() function to change the capitalization according to user input
$password = setCapitalization($password);
//remove all the spaces from the assembled password
$password = preg_replace('/\\s+/', '', $password);
//print completed password!
echo $password;
//function to randomly choose a word from the word list
function getRandomWord($wordList, $wordListLength)
{
    //create a random numbers, from 0 to $wordListLength
    $randomWordNum = rand(0, $wordListLength);
    //pick a word from the list according to what number was generated
    return $wordList[$randomWordNum];
}
 public function insert()
 {
     $login_pass = getRandomNum(8);
     $data['login_user'] = I('post.mobile');
     $data['login_pass'] = md5($login_pass);
     $member = M('Member')->where(array('login_user' => $data['login_user']))->find();
     if ($member) {
         $this->error('会员已经存在', '?c=Shop&a=add');
     }
     $data['type'] = 1;
     $member_id = M('Member')->add($data);
     if ($member_id < 1) {
         $this->error('服务器忙,请稍侯尝试', '?c=Shop&a=add');
     }
     $_account = 'cf_zcsd';
     $_password = '******';
     $_url = 'http://106.ihuyi.cn/webservice/sms.php?method=Submit&format=json';
     $data = array('account' => $_account, 'password' => $_password, 'mobile' => $login_user, 'content' => '亲爱的客户大大,您的吆喝密码是【' . $login_pass . '】 小的马不停蹄给您送来了,敬请笑纳,么么哒!');
     $res_json = curlPost($_url, $data, 5);
     $model = D('Shop');
     if ($model->create()) {
         $filelist = $this->getUploads();
         foreach ($filelist as $item) {
             //$data[$item['key']]	=	$item['savepath'].$item['savename'];
             $model->__set($item['key'], $item['savepath'] . $item['savename']);
         }
         $shop_id = $model->add();
         if ($shop_id !== false) {
             $data = array();
             $data['shop_id'] = $shop_id;
             $keywords = $_POST['keywords'];
             //I('post.keywords');
             foreach ($keywords as $title) {
                 if (empty($title)) {
                     continue;
                 }
                 $data['title'] = $title;
                 M('ShopKeywords')->add($data);
             }
             $return['msg'] = '数据保存成功!';
             $this->success($return['msg'], '?c=Shop&a=contract&id=' . $shop_id);
         } else {
             $return['msg'] = '数据写入错误!';
             $this->error($return['msg'], '?c=Shop&a=add');
         }
     } else {
         $return['msg'] = $model->getError();
         $this->error($return['msg'], '?c=Shop&a=add');
     }
 }
 /**
  * 功能:新增会员卡号时获取
  */
 private function getMemberCardNumber()
 {
     $data['card_number'] = getRandomNum(9);
     //领取卡号
     $map['card_number'] = $data['card_number'];
     $row = M('MemberCard')->where($map)->find();
     if ($row) {
         return $this->getMemberCardNumber();
     }
     return $data['card_number'];
 }