(practical article) PHP Registration and Login Interface implementation case (reproduced in the original study)

Source: Internet
Author: User

At the outset, I think a website registration and login These two functions is very magical, and later to study the discovery of the truth is very simple, then see how to achieve it ....

http://mp.weixin.qq.com/s?__biz=MzIxMDA0OTcxNA==&mid=2654254777&idx=1&sn= 76f8b02e5fbcc7041c9e67b459558194&chksm= 8caa9964bbdd10722309af194a7ad9d30023d41b71d6a56a57199b73b1d5d989ac505d044cc0&mpshare=1&scene=1& Srcid=1103jd2yuyw05doq9lmspfjl#rd

The following small series for everyone to bring a PHP registration and login Interface implementation case (recommended). 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.

I have built several files on my computer:

login.html (Login page)

Register.html (Registration page)

Success.html (Login successful jump page)

Return.html (Registration Success page)

login.php

register.php

The login interface and registration interface, as well as success.html, are not

What are some of the HTML tags are as follows:

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> Login Screen </title>

<body>
<form method= "POST" action= "login.php" >
Account:
<input type= "text" name= "Usernamel" ><br/><br/>
Password:
<input type= "Password" name= "PASSWORDL" >
<input type= "Submit" value= "Login" name= "Subl" >
<a href= "http://127.0.0.1:8080/register.html" > No account, registration </a>
</form>
</body>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> Member Registration </title>

<body>
<form method= "POST" action= "register.php" >
Account
<input type= "text" name= "username" ><br/><br/>
Password
<input type= "password" name= "password" ><br/><br/>
Password Confirmation:
<input type= "Password" name= "Password2" >
<input type= "Submit" value= "register" name= "sub" >
</form>
</body>

Return.html is a successful registration page, there is a section of JS code is used to periodically return to the login interface

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> Untitled Document </title>

<body>
Registration Successful! <br/>
Return to login screen after 5 seconds <br/>
You can also directly click Back to <a href= "http://127.0.0.1:8080/login.html" > login page </a>
<script type= "Text/javascript" >
SetTimeout ("Ren ()", 5000);
Function ren ()
{
Window.location= "http://127.0.0.1:8080/login.html";
}

</script>

</body>

Register.php This is the background page corresponding to the registration page

<?php
$link =mysql_connect ("localhost", "root", "207207");//LINK database
Header ("Content-type:text/html;charset=utf-8");
if ($link)
{
echo "link database success";
$select =mysql_select_db ("login", $link);//Select Database
if ($select)
{
echo "SELECT Database Success!" ";
if (Isset ($_post["sub"]))
{
$name =$_post["username"];
$password 1=$_post["password"];//get form data
$password 2=$_post["Password2"];
if ($name = = "" | | $password 1== "")//determine whether to fill in
{
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.alert "." ("." \""." Please fill in the completed! "." \"".")".";"." </script> ";
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.location= "." \""." Http://127.0.0.1:8080/register.html "." \""." </script> ";
Exit
}
if ($password 1== $password 2)//Confirm the password is correct
{
$STR = "SELECT count (*) from register where username=". "". " $name "." ";
$result =mysql_query ($str, $link);
$pass =mysql_fetch_row ($result);
$PA = $pass [0];
if ($pa ==1)//Determine if the user name already exists in the database table
{

echo "<script type=". " \""." Text/javascript "." \""." > "." Window.alert "." ("." \""." The user name has been registered "." \"".")".";"." </script> ";
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.location= "." \""." Http://127.0.0.1:8080/register.html "." \""." </script> ";
Exit
}


$sql = "INSERT INTO register values (". " \""." $name "." \"".","." \""." $password 1 "." \"".")";/ /Insert registration information into a database table
echo "$sql";
mysql_query ($sql, $link);
mysql_query (' SET NAMES UTF8 ');
$close =mysql_close ($link);
if ($close)
{
echo "Database Off";
echo "Registration is successful! ";
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.location= "." \""." Http://127.0.0.1:8080/return.html "." \""." </script> ";
}
}
Else
{
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.alert "." ("." \""." Passwords are inconsistent! "." \"".")".";"." </script> ";
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.location= "." \""." Http://127.0.0.1:8080/register.html "." \""." </script> ";
}
}
}
}
?>

login.php login interface corresponding to background files

<?php
Header ("Content-type:text/html;charset=utf-8");
$link =mysql_connect ("localhost", "root", "207207");
if ($link)
{
$select =mysql_select_db ("login", $link);
if ($select)
{
if (Isset ($_post["Subl"))
{
$name =$_post["Usernamel"];
$password =$_post["Passwordl"];
if ($name = = "" | | $password = = "")//To determine whether it is empty
{
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.alert "." ("." \""." Please fill in the correct information! "." \"".")".";"." </script> ";
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.location= "." \""." Http://127.0.0.1:8080/login.html "." \""." </script> ";
Exit
}
$str = "Select password from register where username=". "'". " $name "." ";
mysql_query (' SET NAMES UTF8 '); $result =mysql_query ($str, $link);
$pass =mysql_fetch_row ($result);
$PA = $pass [0];
if ($pa = = $password)//Determine if the password is the same as the password at registration
{
echo "Login Successful! ";
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.location= "." \""." Http://127.0.0.1:8080/success.html "." \""." </script> ";
}
{
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.alert "." ("." \""." Login failed! "." \"".")".";"." </script> ";
echo "<script type=". " \""." Text/javascript "." \""." > "." Window.location= "." \""." Http://127.0.0.1:8080/login.html "." \""." </script> ";
}
}

}
}
?>

Free to do nothing to do there are many places to improve, welcome to ask questions to discuss, to provide a more convenient way!

(practical article) PHP Registration and Login Interface implementation case (reproduced in the original study)

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.