Home>Article>Backend Development> How to use php to implement user login

How to use php to implement user login

藏色散人
藏色散人 Original
2021-09-14 10:01:42 8021browse

php method to implement user login: 1. Create a get.php file to obtain user login information; 2. Create a login.php file to implement the login function; 3. Create a logout.php file. It can be used to implement the user logout function.

How to use php to implement user login

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to use php to achieve user login?

Put it on your daily PHP learning routine to record it

I used the bootstrap framework, so this interface should look better

Login page:
How to use php to implement user login
You must enter the correct username, password, and verification code to successfully log in. Otherwise, the following prompt will appear
How to use php to implement user login
How to use php to implement user login
After successful login, the login and registration options switch to User nickname and logout options:
How to use php to implement user login

After successful login:
How to use php to implement user login

Select logout:
How to use php to implement user login

##HTML Code:

 
  • 登录
  • 注册
  • 注销
  • //模态框

    请登录

    How to use php to implement user login

    JS code:

      
    connect.php (connect to database):

    query("set names utf8");
    get.php (get user login information):

    login.php (login):
          

    query("select * from `user` where username='$user' and pwd='$pwd'"); $link = null; $row = $result->fetch();/*读取从数据库获取的数据*/ if ($row) {/*如果数据存在,即用户登录成功*/ $_SESSION['username'] = $row['username']; /*将用户名和昵称存在服务器,可以多个页面使用*/ $_SESSION['nc'] = $row['nc']; $flag=3; }else{/*用户名或密码错误*/ $flag=2; } }else{/*验证码输入错误*/ $flag=1; } echo $flag;
    logout.php (logout):

    Recommended learning: "
          

    PHP Video Tutorial"

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

    Statement:
    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