简单的注册登录(纯手打) [ 2.0 版本 ]
<?php
namespace backend\controllers;
use Yii;
use yii\web\Controller;
class ZiceController extends Controller
{
public $enableCsrfValidation = false;//取消crsf攻击
public $layout = false;//关闭布局
//首页
public function actionIndex()
{
return $this->render('index');
}
//注册
public function actionRegister()
{
$post = $_POST;
if($post)
{
$res = \Yii::$app->db->createCommand()->insert('user',$post)->execute();
if($res){
echo "<script>alert('注册成功,正在前往登录页面');location.href='?r=zice/login'</script>";
}
else{
echo "<script>alert('注册失败,请重新填写');location.href='?r=zice/register'</script>";
}
}
else
{
return $this->render('register');
}
}
//登录
public function actionLogin()
{
$post = isset($_POST)?$_POST:'';
if($post){
$res = \Yii::$app->db->createCommand("SELECT * FROM user WHERE phone='".$post['phone']."' and pwd = '".$post['pwd']."'")->queryOne();
if($res['phone'] == $post['phone']){
if ($res['pwd'] == $post['pwd']){
echo "<script>alert('登录成功,正在跳转');location.href='?r=zice/index'</script>";
}
else{
echo "<script>alert('登录失败,账号或密码错误');location.href='?r=zice/login'</script>";
}
}
else{
echo "<script>alert('登录失败,用户名有误');location.href='?r=zice/login'</script>";
}
}
else{
return $this->render('login');
}
}
}
1196281550
注册时间:2017-10-17
最后登录:2019-10-28
在线时长:2小时23分
最后登录:2019-10-28
在线时长:2小时23分
- 粉丝3
- 金钱65
- 威望40
- 积分485
共 8 条评论
明文存储密码?
也不写session也不写cookie,登录状态跳转就掉
还是$_POST
11111
太lou啦
eee bw?
太out啦
收藏了,谢谢!
少年 请你不要误导大家 真的太low了