基于PHP的登录和注册的功能的实现

1.新建三个html文件,两个php文件和若干个CSS文件和若干个JS文件

2.登录的html页面显示效果图

基于PHP的登录和注册的功能的实现


3.注册的页面的显示效果图

基于PHP的登录和注册的功能的实现

4.登录页面的form表单代码

<div> <img src="https://www.jb51.net/img/logn-tu.gif"/> <form action="login.php" method="post"> <div> <p>用户名:</p> <input type="text" placeholder="手机号/邮箱" /> <p>密码:</p> <input type="password" placeholder="密码可见" /> <br /> <button>登录</button> <p> 没有账号?请 <a href="https://www.jb51.net/regist.html" >注册</a> <a href="#">忘记密码?</a> </p> <div> <a href="#"> <img src="https://www.jb51.net/img/sign-xinlan.gif" /> </a> <a href="#"> <img src="https://www.jb51.net/img/sign-qq.gif" /> </a> <div></div> </div> </div> </form> <div></div> </div>

5.注册页面的form表单代码

<div> <form action="regist.php" method="post"> <div> <p>用户名</p> <input type="text" placeholder="HR了" /> <span></span> </div> <div> <p>输入密码</p> <input type="password" placeholder="请输入密码" /> <span>密码由6-16的字母、数字、符号组成</span> </div> <div> <p>确认密码</p> <input type="password" placeholder="请再次输入密码" /> <span>密码不一致,请重新输入</span> </div> <div> <p>手机号/邮箱</p> <input type="text" placeholder="请输入手机/邮箱验证码" /> <button>获取短信验证码</button> </div> <div> <p>验证码</p> <input type="text" placeholder="请输入验证码" /> </div> <div> <div> <img src="https://www.jb51.net/img/psw-yanzhengtu.gif" /> </div> <p> 看不清楚? <a href="#" >换张图</a> </p> <div></div> </div> <div> <input type="checkbox" /> <p> 我有阅读并同意 <span>《宅客微购网站服务协议》</span> </p> </div> <button type="submit" value="注册">立即注册</button> <p> 已有账号?请 <a href="https://www.jb51.net/login.html" >登录</a> </p> </form> </div><!-- 注册框结束 -->

6.login.php代码

<?php header("Content-type: text/html; charset=utf-8"); $username = $_POST['username']; $password = $_POST['password']; $conn = new mysqli('localhost','root','root','shopping'); if ($conn->connect_error){ echo '数据库连接失败!'; exit(0); }else{ if ($username == ''){ echo '<script>alert("请输入用户名!");history.go(-1);</script>'; exit(0); } if ($password == ''){ echo '<script>alert("请输入密码!");history.go(-1);</script>'; exit(0); } $sql = "select username,password from userinfo where username = '$_POST[username]' and password = '$_POST[password]'"; $result = $conn->query($sql); $number = mysqli_num_rows($result); if ($number) { echo '<script>window.location="index.html";</script>'; } else { echo '<script>alert("用户名或密码错误!");history.go(-1);</script>'; } } ?>

7.regist.php代码

<?php header("Content-type: text/html; charset=utf-8"); $username = $_POST['username']; $password = $_POST['password']; $repassword = $_POST['repassword']; $telphone = $_POST['telphone']; if ($username == ''){ echo '<script>alert("请输入用户名!");history.go(-1);</script>'; exit(0); } if ($password == ''){ echo '<script>alert("请输入密码");history.go(-1);</script>'; exit(0); } if ($password != $repassword){ echo '<script>alert("密码与确认密码应该一致");history.go(-1);</script>'; exit(0); } if($password == $repassword){ $conn = new mysqli('localhost','root','root','shopping'); if ($conn->connect_error){ echo '数据库连接失败!'; exit(0); }else { $sql = "select username from userinfo where username = '$_POST[username]'"; $result = $conn->query($sql); $number = mysqli_num_rows($result); if ($number) { echo '<script>alert("用户名已经存在");history.go(-1);</script>'; } else { $sql_insert = "insert into userinfo (username,password,telphone) values('$_POST[username]','$_POST[password]','$_POST[telphone]')"; $res_insert = $conn->query($sql_insert); if ($res_insert) { echo '<script>window.location="index.html";</script>'; } else { echo "<script>alert('系统繁忙,请稍候!');</script>"; } } } }else{ echo "<script>alert('提交未成功!'); history.go(-1);</script>"; } ?>

8.进入首页后的图片

基于PHP的登录和注册的功能的实现


9.数据库的图片

基于PHP的登录和注册的功能的实现


内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/307a0c7e1fc53b87fbe77dda1266354f.html