Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use php to achieve user login

Shulou Source: shulou.com Published: 2022-06-03 14:43:19 10月01日 Update

This article will explain in detail how to use php to achieve user login, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Php to achieve user login methods: 1, create get.php file, used to obtain user login information; 2, create login.php file, used to achieve login function; 3, create logout.php file, used to achieve user logout function.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How to use php to achieve user login?

PHP study daily, put it on it and record it.

I used the bootstrap framework, so the interface looks better.

Login page:

The user name, password and verification code must be entered correctly in order to log in successfully, otherwise the following prompt appears

After the login is successful, the login and registration options switch to the user nickname and logout options:

After successful login:

Select logout:

HTML Code:

Li.toggle {display: block;} li.toggle1 {display: none;} login registration logout / / modal box × Close Please log in

User name:

Password:

CAPTCHA:

Login off

JS Code:

Function toggle () {$.getJSON ("php/get.php", function (res) {if (res ['flag']) {$(' li.toggle') .hide (); $('li.toggle1') .show ()) $('# nicheng') .html (res ['nc'])} else {$(' li.toggle'). Show (); $('li.toggle1'). Hide ();}});} toggle (); $(' # form_login') .submit (function (e) {e.preventDefault () Var data=$ ('# form_login'). Serialize (); $.getJSON ('php/login.php',data,function (res) {if (res==3) {toggle (); $(' # loginer'). Modal ('hide')) } else if (res==2) {$('# info') .html ('incorrect username or password')} else {$('# info') .html ('incorrect verification code')})}); $('# logout') .click (function () {confirm ('are you sure you want to log out?') ; $.getJSON ('php/logout.php',function (res) {if (res) toggle ();})})

Connect.php (connect to the database):

Tags: User login user name success password data nickname authentication file code information content function database article more logo knowledge article error Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn Linux Microsoft Huawei