本文整理匯總了PHP中MyController::getUserHostAddress方法的典型用法代碼示例。如果您正苦於以下問題:PHP MyController::getUserHostAddress方法的具體用法?PHP MyController::getUserHostAddress怎麽用?PHP MyController::getUserHostAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MyController
的用法示例。
在下文中一共展示了MyController::getUserHostAddress方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: authenticate
public function authenticate()
{
$user = Player::model()->find('email=:user and password=:pass', array(':user' => $this->username, ':pass' => self::hashpwd($this->password)));
if ($user) {
$user->last_login_ip = MyController::getUserHostAddress();
$user->last_login_time = date('Y-m-d H:i:s');
$user->login_times++;
$user->save();
Yii::app()->user->setState('id', $user->id);
return true;
} else {
return false;
}
}
示例2: actionReg
public function actionReg()
{
$email = trim(Yii::app()->request->getParam('email'));
$nick = trim(Yii::app()->request->getParam('nickname'));
$password = trim(Yii::app()->request->getParam('passwd'));
$password2 = trim(Yii::app()->request->getParam('passwd2'));
$refer = trim(Yii::app()->request->getParam('refer', '/'));
if (!preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i', $email)) {
$this->json_return(false, '請輸入一個格式正確的Email地址');
}
if (!$password || $password != $password2) {
$this->json_return(false, '2次輸入的密碼不一致');
}
if (!$nick) {
$this->json_return(false, '請填寫昵稱');
}
if (mb_strlen($nick, 'UTF-8') > 9) {
$this->json_return(false, '昵稱長度請限製在9個字之內');
}
if (Player::model()->find('email=:email', array(':email' => $email))) {
$this->json_return(false, '這個Email已經被注冊了,您是否已經注冊過了呢?');
}
if (Player::model()->find('nickname=:nick', array(':nick' => $nick))) {
$this->json_return(false, '這個昵稱已經被注冊了,換一個吧');
}
$player = new Player();
$player->email = $email;
$player->nickname = $nick;
$player->password = MyUserIdentity::hashpwd($password);
$player->login_times = 0;
$player->b_win = 0;
$player->b_lose = 0;
$player->w_win = 0;
$player->w_lose = 0;
$player->draw = 0;
$player->reg_time = date('Y-m-d H:i:s');
$player->reg_ip = MyController::getUserHostAddress();
$player->last_login_time = date('Y-m-d H:i:s');
$player->last_login_ip = MyController::getUserHostAddress();
$player->score = Yii::app()->params['init_score'];
if ($player->save()) {
$identity = new MyUserIdentity($email, $password);
if ($identity->authenticate()) {
Yii::app()->user->login($identity, 3600);
$this->json_return(true, '恭喜您注冊成功!', $refer);
}
}
$this->json_return(false, '注冊失敗啦,請與管理員聯係。');
}