亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home PHP Framework YII How to implement login in yii

How to implement login in yii

Feb 18, 2020 am 11:01 AM
yii accomplish Log in

How to implement login in yii

How to implement login in yii

1. Create the data table shop_admin

CREATE TABLE `shop_admin` (
  `adminid` int(10) UNSIGNED NOT NULL COMMENT '主鍵ID',
  `adminuser` varchar(32) NOT NULL DEFAULT '' COMMENT '管理員賬號(hào)',
  `adminpass` char(32) NOT NULL DEFAULT '' COMMENT '管理員密碼',
  `adminemail` varchar(50) NOT NULL DEFAULT '' COMMENT '管理員郵箱',
  `logintime` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '登陸時(shí)間',
  `loginip` bigint(20) NOT NULL DEFAULT '0' COMMENT '登陸IP',
  `createtime` int(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '創(chuàng)建時(shí)間'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

How to implement login in yii

2. Login page

<?php
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
$form = ActiveForm::begin([
    &#39;id&#39; => &#39;abc-form&#39;,
    &#39;options&#39; => [&#39;class&#39; => &#39;form-horizontal&#39;],
])?>
<?= $form->field($model, &#39;adminuser&#39;)->textInput([&#39;placeholder&#39; => "用戶名"])->label(&#39;賬號(hào)&#39;) ?>
<?= $form->field($model, &#39;adminpass&#39;)->passwordInput()->label(&#39;密碼&#39;) ?>
<?= Html::submitButton(&#39;提交&#39;) ?>
<?php ActiveForm::end() ?>

3. Controller

Related article tutorial recommendations: yii Tutorial

<?php
namespace app\controllers;
use yii\web\Controller;
use app\models\Admin;
use Yii;
 
class IndexController extends Controller
{
    public function actionIndex()
    {
//      不使用布局
        $this->layout = false;
        $model = new Admin;
//        是否是post提交
        if (Yii::$app->request->isPost) {
//            獲得post提交參數(shù)
            $post = Yii::$app->request->post();
            if($model->login($post)){
                return "登陸成功";
            } else {
                return "登陸失敗";
            }
        } else {
            return $this->render("index", [&#39;model&#39; => $model]);
        }
    }
 
}

4, Model

<?php
namespace app\models;
use yii\db\ActiveRecord;
use Yii;
class Admin extends ActiveRecord
{
    public static function tableName()
    {
        return "{{%admin}}";
    }
 
    public function rules()
    {
        return [
            [&#39;adminuser&#39;, &#39;required&#39;],
            [&#39;adminpass&#39;, &#39;required&#39;],
//           驗(yàn)證密碼是否正確
            [&#39;adminpass&#39;, &#39;validatePass&#39;]
        ];
    }
 
    public function validatePass()
    {
        if (!$this->hasErrors()) {
//            判斷用戶名密碼是否正確
            $data = self::find()
                ->where([&#39;adminuser&#39; => $this->adminuser])
                ->andwhere([&#39;adminpass&#39; => md5($this->adminpass)])
                ->one();
            if (is_null($data)) {
                $this->addError(&#39;adminpass&#39;, &#39;adminuser or adminpass error&#39;);
            }
        }
    }
    public function login($data)
    {
        if($this->load($data) && $this->validate()) {
//            登陸信息寫入session
            $session = Yii::$app->session;
            $session->open();
            $session->set(&#39;adminuser&#39;, $this->adminuser);
//           更新登陸時(shí)間和IP
            $this->updateAll([&#39;logintime&#39; => time(), &#39;loginip&#39; => ip2long(Yii::$app->request->userIP)], [&#39;adminuser&#39; => $this->adminuser]);
            return true;
        }
        return false;
    }
}

For more yiiIntroduction to Programming tutorials, please pay attention to the PHP Chinese website.? ? ? ? ?

The above is the detailed content of How to implement login in yii. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
How do I log in to my previous account on Xiaohongshu? What should I do if the original number is lost after it is reconnected? How do I log in to my previous account on Xiaohongshu? What should I do if the original number is lost after it is reconnected? Mar 21, 2024 pm 09:41 PM

With the rapid development of social media, Xiaohongshu has become a popular platform for many young people to share their lives and explore new products. During use, sometimes users may encounter difficulties logging into previous accounts. This article will discuss in detail how to solve the problem of logging into the old account on Xiaohongshu, and how to deal with the possibility of losing the original account after changing the binding. 1. How to log in to Xiaohongshu’s previous account? 1. Retrieve password and log in. If you do not log in to Xiaohongshu for a long time, your account may be recycled by the system. In order to restore access rights, you can try to log in to your account again by retrieving your password. The operation steps are as follows: (1) Open the Xiaohongshu App or official website and click the &quot;Login&quot; button. (2) Select &quot;Retrieve Password&quot;. (3) Enter the mobile phone number you used when registering your account

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

How to log in if Xiaohongshu only remembers the account? I just remember how to retrieve my account? How to log in if Xiaohongshu only remembers the account? I just remember how to retrieve my account? Mar 23, 2024 pm 05:31 PM

Xiaohongshu has now been integrated into the daily lives of many people, and its rich content and convenient operation methods make users enjoy it. Sometimes, we may forget the account password. It is really annoying to only remember the account but not be able to log in. 1. How to log in if Xiaohongshu only remembers the account? When we forget our password, we can log in to Xiaohongshu through the verification code on our mobile phone. The specific operations are as follows: 1. Open the Xiaohongshu App or the web version of Xiaohongshu; 2. Click the &quot;Login&quot; button and select &quot;Account and Password Login&quot;; 3. Click the &quot;Forgot your password?&quot; button; 4. Enter your account number. Click &quot;Next&quot;; 5. The system will send a verification code to your mobile phone, enter the verification code and click &quot;OK&quot;; 6. Set a new password and confirm. You can also use a third-party account (such as

PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

How to log in to someone else's iQiyi membership account How to log in to someone else's iQiyi membership account How to log in to someone else's iQiyi membership account How to log in to someone else's iQiyi membership account Mar 23, 2024 pm 05:41 PM

There are quite a lot of resources prepared for everyone on the iQiyi app. There are all kinds of videos, and everyone can choose freely. However, there are also some videos here that require your membership. It allows everyone to better watch these videos, and if everyone doesn’t want to waste money by replenishing their membership, they will want to find membership accounts for some of their friends and log in to watch. So what should be done here specifically? If you are a logged-in member, follow the editor to take a look. Tips for logging in with someone else's iQiyi membership: Method 1: Account login After we open the client, there is an icon with the word &quot;My&quot; in the lower right corner. We click on it to enter the personal interface. Frame this place in red

Win11 Tricks Revealed: How to Bypass Microsoft Account Login Win11 Tricks Revealed: How to Bypass Microsoft Account Login Mar 27, 2024 pm 07:57 PM

Win11 tricks revealed: How to bypass Microsoft account login Recently, Microsoft launched a new operating system Windows11, which has attracted widespread attention. Compared with previous versions, Windows 11 has made many new adjustments in terms of interface design and functional improvements, but it has also caused some controversy. The most eye-catching point is that it forces users to log in to the system with a Microsoft account. For some users, they may be more accustomed to logging in with a local account and are unwilling to bind their personal information to a Microsoft account.

Meipian web version login entrance Meipian web version login entrance Mar 23, 2024 am 08:36 AM

Meipian web version login entrance Meipian web version login entrance. Many friends are curious about what the Meipian web version login entrance is. The official website is [https://www.meipian.cn/]. You can enter this page to view it. As for the content of Meipian, the following will bring you a detailed introduction to the official website address of the Meipian web version login portal. Meipian web version login entrance Meipian web page entrance: [https://www.meipian.cn/] 1. Here we can freely publish articles, videos, and talk to express ourselves and share our lives. 2. You can make friends with Chrysanthemum chrysanthemum through the software and get to know more users with the same preferences. 3. You can continue to learn more learning courses in the software and continuously improve yourself.

See all articles