本文整理汇总了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, '注册失败啦,请与管理员联系。');
}