How to use php to implement user login

藏色散人
Release: 2023-03-12 14:24:02
Original
8006 people have browsed it

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:

 
Copy after login
  • 登录
  • 注册
  • 注销
  • //模态框

    请登录

    How to use php to implement user login

    JS code:

      
    Copy after login
    connect.php (connect to database):

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

    
            
    Copy after login
    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;
    Copy after login
    logout.php (logout):

    
            
    Copy after login
    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!

    Related labels:
    php
    source:php.cn
    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
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!