分享一个基于PHP的非常简单基础的注册系统,为了减轻难度没有使用Cookie和Session,数据库大家按照自己需求更改,有问题欢迎联系我。
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < title >Title</ title > </ head > < body > < a href = "join_us.html" > 注册 </ a > < h2 >分开一下</ h2 > < a href = "login.html" > 登录 </ a > </ body > </ html > |
join_us.html
注册页面,发一个表单给add_member.php,使用post。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < title >Title</ title > </ head > < body > < h1 >欢迎加入我们</ h1 > < form action = "add_member.php" method = "post" name = "register_form" > < table > < tr > < td > 用户名: </ td > < td > < input name = "member_name" type = "text" > </ td > </ tr > < tr > < td > 输入密码: </ td > < td > < input name = "member_password" type = "password" > </ td > </ tr > < tr > < td >< input type = "submit" value = "确定" > </ td > </ table > </ form > </ body > </ html > |
add_member.php
稍微用了一下js,也可以用header(),仅测试使用,项目不要傻乎乎的给root权限。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
<?php $account = $_POST [ "member_name" ]; $password = $_POST [ "member_password" ]; //获取字段信息 $link = mysqli_connect( "127.0.0.1" , "root" , "" ) or die ( "连接失败" ); //连接数据库 mysqli_select_db( $link , "jack" ); //连接数据表 $sql = "SELECT * FROM info WHERE Name='$account'" ; $result = mysqli_query( $link , $sql ); //检索数据库同名账户 if (mysqli_num_rows( $result ) != 0) { mysqli_free_result( $result ); mysqli_close( $link ); //释放空间 echo "<script>alert('该用户名已被使用');history.go(-1);</script>" ; //返回 } //同名账户返回注册页 else { $sql = "INSERT INTO info(Name,Password) VALUES( '$account','$password' )" ; mysqli_query( $link , $sql ); //写入 mysqli_free_result( $result ); mysqli_close( $link ); //释放空间 echo "注册成功" ; } //非同名写入数据库 ?> |
login.html
登录页面,发表单给check_password.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" > < title >Title</ title > </ head > < body > < h2 > 欢迎登录 </ h2 > < form action = "check_password.php" method = "post" name = "register_form" > < table > < tr > < td > 用户名: </ td > < td > < input name = "member_name" type = "text" > </ td > </ tr > < tr > < td > 输入密码: </ td > < td > < input name = "member_password" type = "password" > </ td > </ tr > < tr > < td >< input type = "submit" value = "确定" > </ td > </ table > </ form > </ body > </ html > |
check_password.php
验证密码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<?php $account = $_POST [ "member_name" ]; $password = $_POST [ "member_password" ]; //获取字段信息 $link = mysqli_connect( "127.0.0.1" , "root" , "" ) or die ( "连接失败" ); //连接数据库 mysqli_select_db( $link , "jack" ); //连接数据表 $sql = "SELECT * FROM info WHERE Name='$account'AND Password='$password'" ; $result =mysqli_query( $link , $sql ); if (mysqli_num_rows( $result ) == 0) { mysqli_free_result( $result ); mysqli_close( $link ); //释放空间 echo "<script>alert('账户或密码错误');history.go(-1);</script>" ; //返回 } else { mysqli_free_result( $result ); mysqli_close( $link ); //释放空间 echo "登录成功" ; //建议在此处setcookie(); } ?> |
都是很基础的东西,大家多多交流。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_40568075/article/details/83047797