PHP and MySQL database and Web login verification examples in Ubutu 16.04 environment

Source: Internet
Author: User
Tags md5 encryption php and mysql
The following small series for everyone to bring an article Ubutu 16.04 environment, PHP and MySQL database, Web login Verification example explained. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.

Just the latest domain name record passed, the rise suddenly want to do a Web page, although before to record the domain name also has this purpose.

Asked a few people, said that using the Linux build Web site with PHP is very simple, try to do a, here is mainly about the login verification related parts;

The Prime Minister prepares several documents, mainly index.php, conn.php, data.php and login.php;

Login.php is primarily a data-comparison part of the login process, where the include (' conn.php ') content is described below.


<?phpif (!isset ($_post[' submit ')) {exit (' login in error. ');} $username = Htmlspecialchars ($_post[' username '); $password = MD5 ($_post[' password '); include (' conn.php '); echo "$ Password "; $check _query = Mysqli_query ($result," select USERID from USERINFO where email= ' $username ' and password= ' $ Password ' limit 1 '); if ($ret = Mysqli_fetch_array ($check _query)) {echo ' Connect true. ';} else{echo ' Connect false ';}? >

It is also important to note that the $_post is aimed at the contents of method = "post" in form.

Because of the use of MD5 encryption in the way, so to speak, in the background database encryption also need to use the MD5 encryption way to update the data, the specific way is as follows:


UPDATE USERINFO SET PASSWORD = MD5 (' root ') WHERE USERID = 1000;

The table and the specific query location are based on the personal database.

Conn.php is mainly related to MySQL database connection operations, divided into database connection, as well as the Database selection section (note the value of the database connection return value, do not casually up, the back of the reference when it is useful. )


<?phptry{$result = mysqli_connect (' localhost ', ' root ', ' root '), mysqli_select_db ($result, ' Webdatas ');} catch (Exception $e) {echo $e->message; exit;} if (! $result) {return false;} echo "ok\n";? >

The rest of the main is index.php the file is the home page related, I only put the relevant parts of the login to explain (here is the template in the Boostrap, interested can Baidu a bit boostrap)


<?phpsession_start (); include_once (' data.php '); $handle = Db_connect (), if (! $handle) {echo ' did not ' access ' Database ';} else{echo ' connect success '; >

The data.php login sections that are included are as follows:


<p class= "Modal Fade" tabindex= "-1" role= "dialog" id= "Login" > <p class= "modal-dialog" role= "Document" > &L T;p class= "Modal-content" > <p class= "Modal-header" > <button type= "button" class= "Close" data-dismiss= "Modal" aria-label= "Close" ><span aria-hidden= "true" >x</span></button> 

Basic about the Login verification section is these, mainly with the database data comparison, the beginning of the use of symmetric encryption, the way to encrypt the method has not been carefully studied, the opportunity to look at the back of the good.

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.