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

作者:qq_29656961 时间:2024-04-30 08:48:04 

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

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

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

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

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

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


<div class="sign-con w1200">
<img src="img/logn-tu.gif" class="sign-contu f-l"/>
<form action="login.php" method="post">
<div class="sign-ipt f-l">
<p>用户名:</p>
<input type="text" name="username" placeholder="手机号/邮箱" />
<p>密码:</p>
<input type="password" name="password" placeholder="密码可见" />
<br />
<button class="slig-btn">登录</button>
<p>
没有账号?请
<a href="regist.html" rel="external nofollow" >注册</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="wj">忘记密码?</a>
</p>
<div class="sign-qx">
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-r">
<img src="img/sign-xinlan.gif" />
</a>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="qq f-r">
<img src="img/sign-qq.gif" />
</a>
<div style="clear: both;"></div>
</div>
</div>
</form>
<div style="clear: both;"></div>
</div>

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


<div class="password-con registered">
<form action="regist.php" method="post">
<div class="psw">
<p class="psw-p1">用户名</p>
<input type="text" name="username" placeholder="HR了" />
<span class="dui"></span>
</div>
<div class="psw">
<p class="psw-p1">输入密码</p>
<input type="password" name="password" placeholder="请输入密码" />
<span class="cuo">密码由6-16的字母、数字、符号组成</span>
</div>
<div class="psw">
<p class="psw-p1">确认密码</p>
<input type="password" name="repassword" placeholder="请再次输入密码" />
<span class="cuo">密码不一致,请重新输入</span>
</div>
<div class="psw psw2">
<p class="psw-p1">手机号/邮箱</p>
<input type="text" name="telphone" placeholder="请输入手机/邮箱验证码" />
<button>获取短信验证码</button>
</div>
<div class="psw psw3">
<p class="psw-p1">验证码</p>
<input type="text" placeholder="请输入验证码" />
</div>
<div class="yanzhentu">
<div class="yz-tu f-l">
<img src="img/psw-yanzhengtu.gif" />
</div>
<p class="f-l">
看不清楚?
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >换张图</a>
</p>
<div style="clear: both;"></div>
</div>
<div class="agreement">
<input type="checkbox" name="hobby" />
<p>
我有阅读并同意
<span>《宅客微购网站服务协议》</span>
</p>
</div>
<button type="submit" value="注册" class="psw-btn">立即注册</button>
<p class="sign-in">
已有账号?请
<a href="login.html" rel="external nofollow" >登录</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的登录和注册的功能的实现

来源:https://blog.csdn.net/qq_29656961/article/details/78924085

标签:PHP,登录,注册
0
投稿

猜你喜欢

  • 详解golang避免循环import问题(“import cycle not allowed”)

    2024-05-22 10:19:30
  • docker-py 用Python调用Docker接口的方法

    2023-04-07 03:15:46
  • Python +Selenium解决图片验证码登录或注册问题(推荐)

    2022-12-30 05:41:51
  • 浅谈pytorch torch.backends.cudnn设置作用

    2022-06-20 16:25:06
  • go语言中使用timer的常用方式

    2024-05-10 10:57:49
  • Oracle + mybatis实现对数据的简单增删改查实例代码

    2024-01-27 06:14:53
  • Django小白教程之Django用户注册与登录

    2022-01-14 10:30:06
  • AJAX和DOM的运行经验

    2008-05-02 21:05:00
  • Python基础之条件控制操作示例【if语句】

    2021-02-09 09:30:02
  • Python学习之路之pycharm的第一个项目搭建过程

    2022-01-14 23:16:52
  • java 正则表达式获取两个字符中间的字符串方法

    2022-06-17 20:21:29
  • Go语言基础map用法及示例详解

    2024-04-26 17:33:37
  • 浅谈JavaScript中的parseInt()的妙用

    2024-04-19 10:47:52
  • Python实现桶排序与快速排序算法结合应用示例

    2022-10-26 23:33:39
  • js函数setTimeout延迟执行的简单介绍

    2024-05-05 09:15:14
  • PHP设计模式之命令模式示例详解

    2024-05-11 10:11:06
  • MYSQL定时清除备份数据的具体操作

    2024-01-21 02:47:19
  • session 加入mysql库的方法

    2024-01-24 02:51:37
  • python人工智能算法之决策树流程示例详解

    2022-02-27 17:34:31
  • 解析array splice的移除数组中指定键的值,返回一个新的数组

    2023-11-18 09:51:28
  • asp之家 网络编程 m.aspxhome.com