基于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设计模式  Command(命令模式)
Jun 17 PHP
shopex主机报错误请求解决方案(No such file or directory)
Dec 27 PHP
基于MySQL到MongoDB简易对照表的详解
Jun 03 PHP
php实现邮件发送并带有附件
Jan 24 PHP
MongoDB在PHP中的常用操作小结
Feb 20 PHP
php截取字符串之截取utf8或gbk编码的中英文字符串示例
Mar 12 PHP
封装ThinkPHP的一个文件上传方法实例
Oct 31 PHP
PHP实现的迷你漂流瓶
Jul 29 PHP
yii2 页面底部加载css和js的技巧
Apr 21 PHP
PHP简单字符串过滤方法示例
Sep 04 PHP
PHP与以太坊交互详解
Aug 24 PHP
利用PHP扩展Xhprof分析项目性能实践教程
Sep 05 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
php小技巧 把数组的键和值交换形成了新的数组,查找值取得键
2011/06/02 PHP
window.onload 加载完毕的问题及解决方案(下)
2009/07/09 Javascript
JavaScript去掉数组中的重复元素
2011/01/13 Javascript
jquery实现点击弹出层效果的简单实例
2014/03/03 Javascript
javascript 10进制和62进制的相互转换
2014/07/31 Javascript
js+html5操作sqlite数据库的方法
2016/02/02 Javascript
基于HTML模板和JSON数据的JavaScript交互(移动端)
2016/04/06 Javascript
BootStrap 智能表单实战系列(五) 表单依赖插件处理
2016/06/13 Javascript
jQuery选择器_动力节点Java学院整理
2017/07/05 jQuery
详解微信UnionID作用
2019/05/15 Javascript
关于uniApp editor微信滑动问题
2021/01/15 Javascript
原生js实现下拉框选择组件
2021/01/20 Javascript
跟老齐学Python之模块的加载
2014/10/24 Python
python生成IP段的方法
2015/07/07 Python
Python多进程库multiprocessing中进程池Pool类的使用详解
2017/11/24 Python
python初学之用户登录的实现过程(实例讲解)
2017/12/23 Python
Django使用unittest模块进行单元测试过程解析
2019/08/02 Python
如何用Python来理一理红楼梦里的那些关系
2019/08/14 Python
python序列类型种类详解
2020/02/26 Python
Python基于Webhook实现github自动化部署
2020/11/28 Python
python里glob模块知识点总结
2021/01/05 Python
HTML5 Canvas玩转酷炫大波浪进度图效果实例(附demo)
2016/12/14 HTML / CSS
Qoo10台湾站:亚洲领先的在线市场
2018/05/15 全球购物
澳大利亚汽车零部件、音响及配件超市:Automotive Superstore
2018/06/19 全球购物
Kiwi.com中国:找到特价机票并发现新目的地
2019/10/27 全球购物
毕业生动漫设计求职信
2013/10/11 职场文书
电子商务专员岗位职责
2013/12/11 职场文书
国庆节文艺活动方案
2014/02/03 职场文书
劳动竞赛活动方案
2014/02/20 职场文书
生物制药专业求职信
2014/03/11 职场文书
企业宣传工作方案
2014/06/02 职场文书
英文自荐信范文
2015/03/25 职场文书
六一文艺汇演主持词
2015/06/30 职场文书
详解nginx.conf 中 root 目录设置问题
2021/04/01 Servers
教你使用pyinstaller打包Python教程
2021/05/27 Python
浅谈resultMap的用法及关联结果集映射
2021/06/30 Java/Android