Home  >  Article  >  Backend Development  >  Mysql, PDO, php and bootstrap create a login interface plus background processing

Mysql, PDO, php and bootstrap create a login interface plus background processing

WBOY
WBOYOriginal
2016-07-29 09:15:091437browse

前两天用php和Bootstrapt制作了一个登陆界面,其实这只是一个很简单的操作,但对于Bootstrapt新手来说并不显得轻松,因为Bootstrapt里面有一些新词汇,需要慢慢理解并逐渐应用,对于英语基础非常好的能够很快消化,基础稍微差点稍微折腾一番我觉得也能很快就熟练掌握的。废话不多说,先上界面代码。

 

header("Content-Type:text/html; charset=UTF-8");

?>

   

      <strong>Bootstrap</strong> 模板

   

     

     

     

     

     

     

   

   

 

 

   

   

     

   

   

   

   

How can the login interface not have background operations? Here we will use the background operation files The name is doLogin.php, which only adds one do to the login interface, making it easier to understand.

header("Content-Type: text/html; charset=UTF-");

@$login= $_REQUEST['login'];

@$password = $_REQUEST['password'];

if(empty($login) || empty($ password)){

@$msg = "The form is incomplete, please check and refill";

include "login.php";

die;

}

Then all we have to do is to create a database. The database I use is mysql. Since there is not much data that we need to insert in the login interface, I currently just Just insert the login name and password, just do a login verification function. The file name I used here is restaurant.php, below is my code

drop database if exists restaurant;

create database restaurant charset=UTF8;

use restaurant;

create table user(

id int primary key auto_increment,

login varchar(20) not null unique,

password varchar (20) not null

);

insert into user(login, password) values

('a', 'a ');

select * from user; Code, after verifying the database, we still need to verify whether the login name exists in the database. When the condition is true, we will then determine whether the password is correct, so that our verification work can be basically completed.

$pdo = new PDO('mysql:dbname=restaurant; charset=UTF8', 'root');

$stat = $pdo->prepare('select login, password from user where login = :login');

$stat->execute(array('login'=>$login));

@$users = $stat-> ;fetch(PDO::FETCH_NAMED);

if(empty($users)){

@$msg = "Login does not exist";

include

"login.php";

die;}

if($password != $users['password']){

@$ msg = "Password output error";

include

"login.php";

die;

header('Location:main.php');

I would like to say it again here, only when the information entered by the user completely matches the information saved in the database can we say that the verification is passed, and then jump to the main.php page. But at this time, problems arise. For example, a customer feels bored after entering the main.php page and exits. However, from the perspective of customer security, this page must be accessed only after logging in. This cannot be found from the so-called history records. Direct access to the user's homepage. Here I want to involve knowledge about the interaction between the client and the browser. For example, when we view personal information on the homepage of the Industrial and Commercial Bank of China, we are interacting with the browser. The balance of your account is temporarily transmitted from the server, but when Once you log out of your personal homepage and enter again from the history, it will not work. You must log in again, otherwise it is called illegal access. Why? Because after your login name and password are successfully verified, the browser will store a temporary session value during the period before entering the login interface. When you exit the interface, the browser's session value will be logged out. At this time, this The session value will be empty, so even if you want to log in to your personal page before, it will not work. If you think about it, you will know that when you enter illegally, the session value is empty. When it is empty, you will naturally not be able to enter the personal page. The only way you can avoid it is to log in honestly, otherwise I can only say haha . After talking for so long, my purpose is actually to implement this seesion function. We only need to write two lines of code before jumping to the main.php page. The code is as follows:

session_start();

$_SESSION['userID'] = $user['id'];

Then, we have another step, which is to judge the session at the beginning of the main.php page Whether the value is empty, if it is empty, it cannot be accessed

session_start();

@$userID = $_SESSION['userID'];

if(empty($userID)){

$title = 'Serious Warning';

$message = 'You are not logged in, please log in to use';

$jumpUrl = 'login.php';

include 'lib/message.php'; }

Finally, there is one more thing we need to pay attention to. When the session is empty, we cannot jump directly to the login page! There should be a prompt message. Since it is a prompt message, I think it should be a high-end Bootstrapt interface, which is relatively simple and beautiful, although the amount of code is a little more.

header("Content-Type: text/html; charset=UTF-8");

?>

< !DOCTYPE html>

trap

template

< ;meta http-equiv="Content-Type" c/html; charset=UTF-8" charset="UTF-8" >

                                                                ="Bootstrap < ;/script>

  < ;!--[if lt IE 9]>

                                                              

   

 

 

   

 

 

ok,这就是我所说的登录界面,其实我也想说,尼玛不就是一个登录界面嘛,怎么有这么多代码,而且感觉没两句有用的。不过话说回来,前段就是这样,在水平相同的情况下,代码量与界面的美观成正比。

以上就介绍了mysql、PDO、php和bootstrapt制作一个登陆界面外加后台处理,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

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