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

/*
 * 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');
    }

}

猜你喜欢

转载自blog.csdn.net/qq_41054799/article/details/78544860
今日推荐