本文整理汇总了PHP中validate函数的典型用法代码示例。如果您正苦于以下问题:PHP validate函数的具体用法?PHP validate怎么用?PHP validate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register()
{
if (is_post()) {
$this->loadHelper('Validator');
if (captcha()) {
$data = ['email' => validate('email', 'email'), 'username' => validate('required', 'username'), 'password' => password_hash(validate('required', 'register_token'), PASSWORD_BCRYPT), 'token' => str_rand(40)];
if (validator($data)) {
if ($this->user->checkExistUser($data['email'])) {
$data2 = ['firstname' => validate('required', 'firstname'), 'lastname' => validate('required', 'lastname'), 'nickname' => validate('required', 'nickname'), 'major' => validate('required', 'major')];
if (validator($data2)) {
$this->user->createUser($data, $data2);
$validate = $this->user->validate($data['email'], $_POST['register_token']);
if (!empty($validate)) {
$_SESSION['auth'] = $validate;
$_SESSION['user'] = $this->user->getDetail($validate['id']);
cache_forgot('user.members.' . user('major'));
cache_forgot('user.get.members.' . user('major'));
}
}
}
}
}
}
return redirect('');
}
示例2: login
function login()
{
$post = $this->post;
if (count($post)) {
$phone = $post['phone'];
$pass = $post['pass'];
if (!validate('phone', $phone)) {
$this->redirect(_HOST . "login");
}
if (!validate('pass', $pass)) {
$this->redirect(_HOST . "login");
}
$result = $this->load('employee')->login($phone, secret($pass));
if ($result) {
$per = $result['permissions'];
if (!empty($per)) {
$result['permissions'] = array_map("strtolower", unserialize($per));
}
$this->session['user'] = $result;
$this->redirect('index');
} else {
$this->redirect("login");
}
} else {
return $this->view(V_PATH . "login.html", array("css" => CSS, 'host' => _HOST));
}
}
示例3: form_process
function form_process()
{
global $forms;
if (!isset($_REQUEST['form_id'])) {
return;
}
$f = $forms[$_REQUEST['form_id']];
$valid = true;
foreach ($f['params'] as $k => $v) {
$t = explode(';', $v['type']);
$value = $t[0] == 'file' ? $_FILES[$k] : $_REQUEST[$k];
$result = validate($value, $v['type'], $k);
if ($result === true) {
$GLOBALS[$k] = $value;
} else {
form_add_error($_REQUEST['form_id'], $result);
$valid = false;
}
}
if ($f['method'] == 'post') {
form_validate();
}
if ($valid && $f['action']) {
$f['action']();
}
}
示例4: index
function index()
{
$id = $this->u['id'];
// update password
$conf = array('password' => 'required|comparetopwd', 'repassword' => 'required');
$err = validate($conf);
if ($err === TRUE) {
if (!load('m/user_m')->checkpwd($id, $_POST['oldpassword'])) {
redirect(BASE . 'account/', '原密码错误');
}
$_POST['post_time'] = $_POST['update_time'] = time();
load('m/user_m')->update_user($id);
redirect(BASE . 'account/', '修改成功');
} else {
if (isset($_POST['email']) || isset($_POST['username'])) {
$_POST['post_time'] = $_POST['update_time'] = time();
load('m/user_m')->update($id);
redirect(BASE . 'account', '修改成功');
} else {
$param['val'] = array_merge($_POST, load('m/user_m')->get($id));
$param['err'] = $err;
$this->display('v/user/add', $param);
}
}
// update password
}
示例5: create
public function create($options = array())
{
$valid = validate($options, $this->data_types, array('name'));
// Make sure all the options are valid
if ($valid === true) {
// See if this record already exists
$options['slug'] = generateSlug($options['name']);
$tag = $this->read("tags.slug = '" . $options['slug'] . "'", 1, 1);
// If not, add it
if (!isset($tag->tag_id)) {
$q = $this->db->insert_string($this->table, $options);
$res = $this->db->query($q);
// Check for errors
$this->sendException();
// If good, return full label
if ($res === true) {
$tag_id = $this->db->insert_id();
return $this->read($tag_id);
}
// Else return error
return false;
}
// If already exists, just return it
return $tag;
}
return formatErrors($valid);
}
示例6: __construct
function __construct($conn, $peer_id, $prjm_id = 0, $selName = 'prjm_id')
{
global $_SESSION;
global $_REQUEST;
$this->dbConn = $conn;
$this->peer_id = $peer_id;
$this->prjm_id = $prjm_id;
$this->selectorName = $selName;
if (isset($_SESSION[$this->selectorName])) {
$this->prjm_id = $_SESSION[$this->selectorName];
}
if (isset($_REQUEST[$this->selectorName])) {
$newSelect = validate($_REQUEST[$this->selectorName], 'integer', $this->prjm_id);
if ($this->prjm_id != $newSelect) {
$this->selectionChanged = true;
}
$this->prjm_id = $newSelect;
}
if ($this->prjm_id === 0) {
// only guess if undefined.
$this->prjm_id = $this->guessPrjMid($this->peer_id);
}
if (hasCap(CAP_SELECT_ALL)) {
$this->isAdmin = 'true';
} else {
//$this->whereClause =" tutor_id={$peer_id} ";
//$this->extraJoin = " tutor_my_project_milestones({$peer_id}) tmpm on(pm.prjm_id=tmpm.prjm_id) ";
}
}
示例7: handleLogin
public function handleLogin(Request $request, UserRepository $users)
{
$this->validate($request, ['identification' => 'required', 'password' => 'required|min:6|max:16']);
$identification = $request->input('identification');
// guess type of identification
$auth_type = validate($identification, 'email') ? "email" : "username";
event(new Events\UserTryToLogin($identification, $auth_type));
// Get user instance from repository.
// If the given identification is not registered yet,
// it will return a null value.
$user = $users->get($identification, $auth_type);
if (session('login_fails', 0) > 3) {
if (strtolower($request->input('captcha')) != strtolower(session('phrase'))) {
return json(trans('auth.validation.captcha'), 1);
}
}
if (!$user) {
return json(trans('auth.validation.user'), 2);
} else {
if ($user->checkPasswd($request->input('password'))) {
Session::forget('login_fails');
Session::put('uid', $user->uid);
Session::put('token', $user->getToken());
// time in minutes
$time = $request->input('keep') == true ? 10080 : 60;
event(new Events\UserLoggedIn($user));
return json(trans('auth.login.success'), 0, ['token' => $user->getToken()])->withCookie('uid', $user->uid, $time)->withCookie('token', $user->getToken(), $time);
} else {
Session::put('login_fails', session('login_fails', 0) + 1);
return json(trans('auth.validation.password'), 1, ['login_fails' => session('login_fails')]);
}
}
}
示例8: testDobAgeMin
function testDobAgeMin()
{
$input['dob'] = '01/01/' . (date('Y') - 15);
$valid = array('dob' => array('type' => 'dob', 'min' => 18));
validate($valid, $input, $errors);
$this->assertTrue(!empty($errors['dob']));
}
示例9: nav
function nav()
{
unset($_SESSION['index_class']);
unset($_SESSION['editmix_class']);
unset($_SESSION['validate_class']);
unset($_SESSION['makemix_class']);
unset($_SESSION['mwbedocs_class']);
unset($_SESSION['upfiles_class']);
if ($_SESSION['action'] == "index") {
index();
} elseif ($_SESSION['action'] == "makemix") {
makemix();
} elseif ($_SESSION['action'] == "upfiles") {
upfiles();
} elseif ($_SESSION['action'] == "verify") {
verify();
} elseif ($_SESSION['action'] == "validate") {
validate();
} elseif ($_SESSION['action'] == "editmix") {
editmix();
} elseif ($_SESSION['action'] == "mwbedocs") {
mwbedocs();
} elseif ($_SESSION['action'] == "delmix") {
delmix();
} else {
index();
}
}
示例10: validateAndSave
private function validateAndSave($options, $overwriteCreatedOn)
{
$valid = validate($options, $this->data_types, array('title', 'url'));
// Make sure all the options are valid
if ($valid === true) {
// Make sure url doesn't already exist
$md5 = md5($options['url']);
$mark = $this->read("url_key = '" . $md5 . "'", 1, 1);
// If not found, add it
if (!isset($mark->mark_id)) {
if ($overwriteCreatedOn || empty($options['created_on'])) {
$options['created_on'] = date('Y-m-d H:i:s');
}
$options['url_key'] = $md5;
$q = $this->db->insert_string('marks', $options);
$res = $this->db->query($q);
// Check for errors
$this->sendException();
// Return mark_id
if ($res === true) {
$mark_id = $this->db->insert_id();
return $this->read($mark_id);
}
return false;
}
// If already exists, just return it
return $mark;
}
return formatErrors($valid);
}
示例11: calculate
function calculate($goal, $distance, $isKM, $showKM) {
if (!validate($goal)) {
echo "Invalid time format. Please enter MM:SS or HH:MM:SS.";
return;
}
$goalInSec = convertToSeconds($goal);
$numSplits = getNumSplits($distance, $isKM, $showKM);
$averagePaceInSec = getAveragePaceInSeconds($goalInSec, $numSplits);
echo "Distance: ";
echo $numSplits . ($showKM ? "km" : " miles");
echo "<br/>";
echo "Goal: " . $goal;
echo "<br/>";
echo "<br/>";
echo "Average pace: " . convertToHHMMSS($averagePaceInSec);
echo "/" . ($showKM ? "km" : "mile");
echo "<br/>";
getSplits($averagePaceInSec, $numSplits);
if (floor($numSplits) != $numSplits) {
echo "Finish: " . $goal;
}
}
示例12: create
public function create($options = array())
{
$smart_label = isset($options['domain']) ? true : false;
// If a smart label, set the required fields
if ($smart_label === true) {
$required = array('smart_label_id', 'domain', 'smart_key');
} else {
$required = array('name', 'slug');
}
$valid = validate($options, $this->data_types, $required);
// Make sure all the options are valid
if ($valid === true) {
// If not, add it
$options['created_on'] = date('Y-m-d H:i:s');
$q = $this->db->insert_string($this->table, $options);
$res = $this->db->query($q);
// Check for errors
$this->sendException();
// If good, return full label
if ($res === true) {
$cache_key = isset($options['user_id']) ? $this->cache_id . $options['user_id'] . '-*' : $this->cache_id . 'labels-*';
$this->removeCacheKey($cache_key);
$label_id = $this->db->insert_id();
return self::readComplete($label_id);
}
// Else return error
return false;
}
return formatErrors($valid);
}
示例13: create
/**
* Creates new token
* @param array $options Token data
* @return Ambigous <boolean, mixed, array>
*/
public function create($options = array())
{
$required = array('token_type');
$valid = validate($options, $this->data_types, $required);
// Make sure all the options are valid
if ($valid === true) {
// If you made it this far, we need to add the record to the DB
$options['created_on'] = date("Y-m-d H:i:s");
$confExpireTime = $this->config->item('forgot_password_token_valid_seconds');
$options['valid_until'] = date("Y-m-d H:i:s", time() + (empty($confExpireTime) ? self::DEFAULT_TOKEN_VALID_TIME_SECONDS : $confExpireTime));
// Generate random token
$this->load->library('uuid');
do {
$options['token_value'] = $this->uuid->v4(true) . $this->uuid->v4(true);
$total = $this->count("token_value = '" . $options['token_value'] . "'");
} while ($total > 0);
// This should never happen according to UUID generation
// Add record
$q = $this->db->insert_string('tokens', $options);
$res = $this->db->query($q);
// Check for errors
$this->sendException();
if ($res === true) {
$token_id = $this->db->insert_id();
return $this->read($token_id);
} else {
return formatErrors('Eek this is akward, sorry. Something went wrong. Please try again.');
}
}
return formatErrors($valid);
}
示例14: validateAndSave
private function validateAndSave($options, $overwriteCreatedOn)
{
$valid = validate($options, $this->data_types, array('user_id', 'mark_id'));
// Make sure all the options are valid
if ($valid === true) {
if ($overwriteCreatedOn || empty($options['created_on'])) {
$options['created_on'] = date('Y-m-d H:i:s');
}
$q = $this->db->insert_string('users_to_marks', $options);
$res = $this->db->query($q);
// Check for errors
$this->sendException();
// If good, return full record
if ($res === true) {
// Remove cache for this user
$this->removeCacheKey($this->cache_id . $options['user_id'] . '-*');
// Get info and return it
$user_mark_id = $this->db->insert_id();
return $this->readComplete($user_mark_id);
}
// Else return error
return false;
}
return formatErrors($valid);
}
示例15: get
function get()
{
$phone = $this->post["phone"];
if (validate("phone", $phone)) {
$result = $this->load("guest")->findPhone($phone);
if ($result) {
//send sms
$sms = create_sms_code(6);
$this->session["sms"] = $sms;
$send_result = send_sms_code($phone, "验证码" . $sms);
// ok == 1
if ($send_result == 1) {
$this->session['sms'] = $sms;
$this->session['phone'] = $phone;
return json_encode(array('error_code' => 0));
} else {
return json_encode(array('error_code' => 4));
}
} else {
return json_encode(array("error_code" => 2));
}
} else {
return json_encode(array("error_code" => 3));
}
}