Implementation case of php registration and login interface
This article mainly introduces the implementation case of PHP registration and login interface. Interested friends can refer to it. I hope it will be helpful to everyone.
At first I thought the two functions of registration and login on a website were magical. Later, I did some research and found that the truth is actually very simple. Let’s take a look at how to implement it. . . .
I created several files on my computer:
login.html (login page)
register.html (Registration page)
success.html (Login success redirect page)
return.html (Registration success page )
login.php
register.php
Login interface and registration interface and success.html are combined There is no
, everything is just some html tags as follows:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>登录界面</title> </head> <body> <form method="post" action="login.php"> 账号: <input type="text" name="usernamel"><br/><br/> 密码: <input type="password" name="passwordl"> <input type="submit" value="登录" name="subl"> <a href="http://127.0.0.1:8080/register.html">没有账号,注册</a> </form> </body> </html>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>会员注册</title> </head> <body> <form method="post" action="register.php"> 账 户: <input type="text" name="username"><br/><br/> 密 码: <input type="password" name="password"><br/><br/> 密码确认: <input type="password" name="password2"> <input type="submit" value="注册" name="sub"> </form> </body> </html>
return.html is the page that appears after successful registration. There is a js code in it that is used to return to the login interface regularly
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> </head> <body> 注册成功!<br/> 5秒后返回登录界面<br/> 你也可以直接点击回到<a href="http://127.0.0.1:8080/login.html">登录页面</a> <script type="text/javascript"> setTimeout("ren()",5000); function ren() { window.location="http://127.0.0.1:8080/login.html"; } </script> </body> </html>
register.php It is the background page corresponding to the registration page
<?php $link=mysql_connect("localhost","root","207207");//链接数据库 header("Content-type:text/html;charset=utf-8"); if($link) { //echo"链接数据库成功"; $select=mysql_select_db("login",$link);//选择数据库 if($select) { //echo"选择数据库成功!"; if(isset($_POST["sub"])) { $name=$_POST["username"]; $password1=$_POST["password"];//获取表单数据 $password2=$_POST["password2"]; if($name==""||$password1=="")//判断是否填写 { echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."请填写完成!"."\"".")".";"."</script>"; echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/register.html"."\""."</script>"; exit; } if($password1==$password2)//确认密码是否正确 { $str="select count(*) from register where username="."'"."$name"."'"; $result=mysql_query($str,$link); $pass=mysql_fetch_row($result); $pa=$pass[0]; if($pa==1)//判断数据库表中是否已存在该用户名 { echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."该用户名已被注册"."\"".")".";"."</script>"; echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/register.html"."\""."</script>"; exit; } $sql="insert into register values("."\""."$name"."\"".","."\""."$password1"."\"".")";//将注册信息插入数据库表中 //echo"$sql"; mysql_query($sql,$link); mysql_query('SET NAMES UTF8'); $close=mysql_close($link); if($close) { //echo"数据库关闭"; //echo"注册成功!"; echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/return.html"."\""."</script>"; } } else { echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."密码不一致!"."\"".")".";"."</script>"; echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/register.html"."\""."</script>"; } } } } ?>
login.php login interface corresponding to the 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=="")//判断是否为空 { echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."请填写正确的信息!"."\"".")".";"."</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');20 $result=mysql_query($str,$link); $pass=mysql_fetch_row($result); $pa=$pass[0]; if($pa==$password)//判断密码与注册时密码是否一致 { echo"登录成功!"; echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/success.html"."\""."</script>"; } { echo"<script type="."\""."text/javascript"."\"".">"."window.alert"."("."\""."登录失败!"."\"".")".";"."</script>"; echo"<script type="."\""."text/javascript"."\"".">"."window.location="."\""."http://127.0.0.1:8080/login.html"."\""."</script>"; } } } } ?>
I still have a lot to improve when I have nothing to do. You are welcome to ask questions and discuss and provide easier methods!
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
phpWhat are the steps to use redis long connection
phpDetailed explanation of application containerization and deployment
##phpHow to implement data export
phpSimple winning algorithm example
##
The above is the detailed content of Implementation case of php registration and login interface. For more information, please follow other related articles on the PHP Chinese website!

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.