yii框架登录最简单便捷代码

来源:互联网 发布:重庆大学软件学院 编辑:程序博客网 时间:2024/06/03 10:17
/* * yii登录传html页面 */public function actionLogin(){    return $this->render('login.html');}/* * 登录接收html页面的值 *  */public function actionLogin_do(){    $db = yii::$app->db;    $data = $_POST;//接收表单页面的值    if($data){        $username = $data['username'];        $password = $data['password'];    }    $sql = "select * from admin where username = '$username' and password = '$password'";    $arr = $db->createCommand($sql)->queryAll();    if($arr){        echo "alert(登录成功)";        $this->redirect('index.php?r=index/index');    }else{        echo "alert(登录失败)";        $this->redirect('index.php?r=index/login');    }}
原创粉丝点击