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


Posted in PHP onAugust 06, 2020

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的登录和注册的功能的实现

到此这篇关于基于PHP的登录和注册的功能的实现的文章就介绍到这了,更多相关PHP实现登录和注册的功能内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

PHP 相关文章推荐
php中根据变量的类型 选择echo或dump
Jul 05 PHP
使用php+apc实现上传进度条且在IE7下不显示的问题解决方法
Apr 25 PHP
php修改NetBeans默认字体的大小
Jul 02 PHP
php字符串截取的简单方法
Jul 04 PHP
php最简单的删除目录与文件实现方法
Nov 28 PHP
php+html5使用FormData对象提交表单及上传图片的方法
Feb 11 PHP
浅谈php的优缺点
Jul 14 PHP
PHP合并数组函数array_merge用法分析
Feb 17 PHP
php双层循环(九九乘法表)
Oct 23 PHP
PHP实现找出链表中环的入口节点
Jan 16 PHP
PHP实现通过CURL上传文件功能示例
May 30 PHP
laravel执行php artisan migrate报错的解决方法
Oct 09 PHP
php中try catch捕获异常实例详解
Aug 06 #PHP
PHP日期和时间函数的使用示例详解
Aug 06 #PHP
Apache+PHP+MySQL搭建PHP开发环境图文教程
Aug 06 #PHP
PHP文件打开关闭及读写操作示例解析
Aug 06 #PHP
PHP中-&gt;和=&gt;的含义及使用示例解析
Aug 06 #PHP
基于PHP实现用户登录注册功能的详细教程
Aug 04 #PHP
PHP与Web页面的交互示例详解二
Aug 04 #PHP
You might like
通过JavaScript或PHP检测Android设备的代码
2011/03/09 PHP
php以post形式发送xml的方法
2014/11/04 PHP
js实现ASP分页函数 HTML分页函数
2006/09/22 Javascript
在模板页面的js使用办法
2010/04/01 Javascript
JavaScript面向对象设计二 构造函数模式
2011/12/20 Javascript
JQuery 中几个类选择器的简单使用介绍
2013/03/14 Javascript
js保留两位小数使用toFixed实现
2013/07/29 Javascript
jQuery列表拖动排列具体实现
2013/11/04 Javascript
jquery设置按钮停顿3秒不可用
2014/03/07 Javascript
javascript setinterval 的正确语法如何书写
2014/06/17 Javascript
一个用jquery写的判断div滚动条到底部的方法【推荐】
2016/04/29 Javascript
jquery解析XML及获取XML节点名称的实现代码
2016/05/18 Javascript
jQuery进阶实践之利用最优雅的方式如何写ajax请求
2017/12/20 jQuery
详解基于iview-ui的导航栏路径(面包屑)配置
2019/02/22 Javascript
javascrit中undefined和null的区别详解
2019/04/07 Javascript
小程序获取当前位置加搜索附近热门小区及商区的方法
2019/04/08 Javascript
D3.js(v3)+react 实现带坐标与比例尺的柱形图 (V3版本)
2019/05/09 Javascript
vue中实现图片压缩 file文件的方法
2020/05/28 Javascript
Element Steps步骤条的使用方法
2020/07/26 Javascript
python调用windows api锁定计算机示例
2014/04/17 Python
零基础写python爬虫之爬虫的定义及URL构成
2014/11/04 Python
Python中的urllib模块使用详解
2015/07/07 Python
详解Python命令行解析工具Argparse
2016/04/20 Python
动感网页相册 python编写简单文件夹内图片浏览工具
2016/08/17 Python
Python实现备份MySQL数据库的方法示例
2018/01/11 Python
TensorFlow实现RNN循环神经网络
2018/02/28 Python
django框架基于queryset和双下划线的跨表查询操作详解
2019/12/11 Python
通过代码简单了解django model序列化作用
2020/11/12 Python
Python爬虫爬取微博热搜保存为 Markdown 文件的源码
2021/02/22 Python
食品采购员岗位职责
2014/04/14 职场文书
nginx作grpc的反向代理踩坑总结
2021/07/07 Servers
关于SpringBoot 使用 Redis 分布式锁解决并发问题
2021/11/17 Redis
分享3个非常实用的 Python 模块
2022/03/03 Python
灵能百分百第三季什么时候来?
2022/03/15 日漫
VUE递归树形实现多级列表
2022/07/15 Vue.js
MySQL性能指标TPS+QPS+IOPS压测
2022/08/05 MySQL