At the outset, I think a Web site registration and login to these two functions is very magical, and then their own research to find the truth is very simple, then see how to achieve it ....
I've built a couple of 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 did not
What are some of the HTML tags are as follows:
Return.html is registered after the successful presentation of the page, there is a section of JS code is used to return to the login interface regularly
Register.php This is the background page corresponding to the registration page
<?php $link =mysql_connect ("localhost", "root", "207207");//Linked Database header ("Content-type:text/html;charset=utf-8")
;
if ($link) {//echo "linked database succeeded"; $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"];//obtain the form data $password 2=$_post["Password2"]; if ($name = = "" | | $password 1== "")//to determine whether to fill out {echo "<script type=". \""." Text/javascript "." \""." > "." Window.alert "." ("." \""." Please fill in the complete! "." \"".")".";"."
</script> "; echo "<script type=". \""." Text/javascript "." \""." > "." Window.location= "." \""." Http://127.0.0.1:8080/register.html "." \""."
</script> ";
Exit } if ($password 1== $password 2)//Confirm 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 {echo <script type= is already present in the database table. \""." 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 the registration information into the database table//echo "$sql";
mysql_query ($sql, $link);
mysql_query (' SET NAMES UTF8 ');
$close =mysql_close ($link);
if ($close) {//echo "database shutdown"; echo "Registered successfully!
"; echo "<script type=". \""." Text/javascript "." \""." > "." Window.location= "." \""." Http://127.0.0.1:8080/return.html "." \""."
</script> "; } else {echo ' <script type= '. \""." Text/javascript "." \""." > "." Window.alerT "." ("." \""." Password inconsistent! "." \"".")".";"."
</script> "; echo "<script type=". \""." Text/javascript "." \""." > "." Window.location= "." \""." Http://127.0.0.1:8080/register.html "." \""."
</script> "; }}}?>
Login.php Login interface corresponding background file
<?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 = = "")//judge whether 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)//To determine the password and registration when the password is consistent {echo Login success!
"; 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> "; }}}?>
I have nothing to do and there are many to improve the place, welcome to ask questions, to provide a more convenient way!
The above is a small series for everyone to bring the PHP registration and login interface of the implementation of the case (recommended) All content, I hope that we support cloud Habitat Community ~