public function register()
 {
     $user_name = I('post.username');
     $user_email = I('post.email');
     $user_password = I('post.password');
     $user_password_confirm = I('post.password_confirm');
     //$data = array('user_name'=>$user_name,'user_email'=>$user_email,'user_password'=>$user_password,'user_password_confirm'=>$user_password_confirm);
     //条件判断
     if (empty($user_name)) {
         $this->ajaxReturn(array('error' => 1, 'msg' => '用户名不能为空!'));
         return;
     }
     if (empty($user_email)) {
         $this->ajaxReturn(array('error' => 1, 'msg' => '邮箱不能为空!'));
         return;
     }
     if (empty($user_password)) {
         $this->ajaxReturn(array('error' => 1, 'msg' => '密码不能为空!'));
         return;
     }
     if (!check_username_format($user_name)) {
         $this->ajaxReturn(array('error' => 1, 'msg' => '请检查你的用户名格式!'));
         return;
     }
     //用户名格式验证
     if (!check_email_format($user_email)) {
         $this->ajaxReturn(array('error' => 1, 'msg' => '请检查你的邮箱格式!'));
         return;
     }
     //邮箱格式验证
     if (strlen($user_password) < 6) {
         $this->ajaxReturn(array('error' => 1, 'msg' => '密码不能小于6位!'));
         return;
     }
     //密码长度验证
     if ($user_password !== $user_password_confirm) {
         $this->ajaxReturn(array('error' => 1, 'msg' => '两次输入的密码不一致!'));
         return;
     }
     //录入操作
     $user_salt = get_random_str(6);
     //盐值
     $encrypt_times = rand(1, 10);
     //encrypy times 加密次数
     for ($i = 0; $i < $encrypt_times; $i++) {
         $user_password = md5($user_password . $user_salt);
     }
     //加密
     $user = array('user_name' => $user_name, 'user_email' => $user_email, 'user_password' => $user_password, 'user_salt' => $user_salt, 'user_encrypt_times' => $encrypt_times);
     $result = $this->user_model->add($user);
     if ($result !== false) {
         $this->ajaxReturn(array('error' => 0, 'msg' => '注册成功!'));
     } else {
         $this->ajaxReturn(array('error' => 1, 'msg' => '注册失败!'));
     }
 }
Beispiel #2
0
/**
 * function select_random()
 * This function is given a string of <li>'s it is then converted into PHP code so that a random option can be selected
 * @param string $random_options - a string of <li>this</li><li>that</li> options to be made into an array and PHP code
 * @return array $array - the clean array
**/
function select_random($random_options)
{
    //echo "HERE WITH ".htmlentities($random_options);
    //initialise php code string
    $str = "";
    //check if there is another random in here
    $find = "#<random>(.*)</random>#is";
    if (preg_match($find, $random_options, $matches)) {
        //found a match and recall this function
        $replace = select_random($matches[1]);
        $find = "#<random>(.*)</random>#is";
        $random_options = preg_replace($find, $replace, $random_options);
    }
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Building an array to select random option from", 4);
    $arrayname = "\$" . get_random_str();
    //split up the <li>'s
    $random_options = preg_split('#<li>|</li>#', $random_options);
    //remove any blanks from array
    $random_options = remove_nulls_from_array($random_options);
    //count the total options
    $mx = count($random_options) - 1;
    //add to php code string
    $str .= "'; \r\n\r\n{$arrayname} = rand(0,{$mx});\r\n\r\n";
    //build big if else so that we can select a random options later
    foreach ($random_options as $index => $value) {
        if ($index == 0) {
            $str .= "if(" . $arrayname . "=='" . $index . "'){\r\n\t\$tmp_botsay.= '" . $value . "'; }\r\n";
        } elseif (count($random_options) - 1 == $index) {
            $str .= "else{\r\n\t\$tmp_botsay.= '" . $value . "'; }\r\n\r\n";
            $str .= "\$tmp_botsay .= '";
        } else {
            $str .= "elseif(" . $arrayname . "=='" . $index . "'){\r\n\t\$tmp_botsay.= '" . $value . "'; }\r\n";
        }
    }
    //return the php code string
    runDebug(__FILE__, __FUNCTION__, __LINE__, "Built PHP code string so that we can select option later: {$str}", 4);
    return $str;
}