MySQL, PDO, PHP and BOOTSTRAPT make a login interface plus background processing

Source: Internet
Author: User
The first two days with PHP and BootstrapT made a landing interface, in fact, this is just a very simple operation, but for BootstrapT Novice does not seem easy, because Bootstrap T there are some new words, need to slowly understand and gradually apply, for the English Foundation very good can quickly digest, the foundation slightly almost a little toss I think also can be mastered quickly. Nonsense not much to say, first on the interface code.

Header ("content-type:text/html; Charset=utf-8 ");

?>

<strong>Bootstrap</strong> templates

x

Login Box

Login interface How can no background operation, here we will be the background operation of the file name named dologin.php, only than the login interface add a do, easy to understand.

Header ("content-type:text/html; Charset=utf-");

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

@ $password = $_request[' password ');

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

@ $msg = "Incomplete filling of form, please check and re-fill";

include "Login.php";

Die

}

Then we have to do is to build a database, the database I use is MySQL, because the login interface we need to insert a few data, I currently only insert login name and password bar, just do a login verification function on the line. The file name I used in this is restaurant.php, and here's 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 () is not null unique,

Password varchar () NOT NULL

);

Insert INTO user (login, password) values

(' A ', ' a ');

select * from user;

Then we should also implement the validation of the database in the Dologin, verify that the database is very simple, only 4 lines of code, after the validation of the database, we also need to verify the login name in the database exists, when the condition is true, we determine whether the password is correct, So that our verification work can be said to be basically complete.

$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 name does not exist";

include "Login.php";

Die

}

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

@ $msg = "Password output error";

include "Login.php";

Die

}

Header (' Location:main.php ');

Here I would like to re-say that when the user input information and the information stored in the database is fully compliant, we can say that the verification passed, and then jump to mian.php this page. But this time the problem arises, such as the customer entered mian.php this page feel very bored on the exit, but to the customer security point of view is said to be able to access the page after login, not from the so-called history to find the user's homepage directly into. Here I want to be involved in a client-browser interaction knowledge, such as when we view personal information on the ICBC home page to interact with the browser, the balance of your account is temporarily transferred from the server, but when you exit the profile you are again from the history of the time to enter, you must re-login , otherwise this is called illegal access. Why, because after your login password verification success to the login screen before the time the browser will store a temporary session value, when you exit the interface when the browser session value will be written off, then this session value will be empty, This is even if you want to log in before your personal page is not. If you think about it, you'll know when you're trespassing. The session value is empty, is empty when nature can not enter the personal page, you want to not empty the only way is to honestly login, otherwise I can only say hehe. I've been saying this for a long time. In fact, my goal is to achieve this seesion function, we only need to jump to mian.php this page before writing two lines of code, the code is as follows:

Session_Start ();

$_session[' UserID '] = $user [' id '];

Then, we have a step, that is, in the beginning of the mian.php page to determine whether the session value is empty, is empty can not access

Session_Start ();

@ $userID = $_session[' UserID '];

if (empty ($userID)) {

$title = ' severe warning ';

$message = ' You have not logged in, please log in and use ';

$JUMPURL = ' login.php ';

include ' lib/message.php ';

Die

}

Finally, we need to note that when the session is empty, we can not jump directly to the login page! Should give a hint message, since it is a prompt message I think it should come to a high-end BootstrapT interface, relatively concise and beautiful, although the amount of code a little bit more.

Header ("content-type:text/html; Charset=utf-8 ");

?>

<strong>Bootstrap</strong> templates

"Class=" btn btn-default btn-sm "> OK

OK, this is what I call the login interface, in fact, I also want to say, is not a login interface, how there are so many code, and feel no two words useful. But then again, the previous paragraph is this way, in the same level of the situation, the code volume and the interface is directly proportional to the aesthetics.

The above describes the MySQL, PDO, PHP and bootstrapt to make a landing interface and background processing, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.