注册登陆界面开发记录

10 篇文章 0 订阅
4 篇文章 0 订阅

要实现注册登入,一定是要有后端数据库的参与的,把每个成员信息写成记录插入表中实现注册

html中建立form表单

<div class="section">
            <form name="MyForm" method="POST" action="login.php">
                <div class= "input">
                    <label name="username">用户名</label><br>
                    <input type="text" name="username" class="form">
                </div>
                <div>
                    <label name="id">账号</label><br>
                    <input type="text" name="id" class="form">
                </div>
                <div>
                    <label name="password">密码</label><br>
                    <input type="password" name="password" class="form">
                </div>
                <div>
                    <input type="submit" name="submit" value="注册" class="submit">
                </div>    
            </form>
        </div>

连接服务器

<?php
    header('Content-type:text/html;charset=utf-8');
    $link=mysqli_connect('localhost','root','','login');
    if ($link->connect_error) {
        die("连接错误: " . $link->connect_error);
    }

处理参数

实现对输入的参数进行筛选,要符合规定条件

$username = $_POST['username'];
    $id = $_POST['id'];
    $password = $_POST['password'];

    if (strlen($username) == 0){   
        die("请输入用户名");
    }

    if (is_numeric($id)){
        if (strlen($id)<8||strlen($id)>15){   
            die("请输入8到15位的账号");
        }
    }
    else{
        die("账号中只能由数字组成");
    }

    if (strlen($password)<8||strlen($password)>15){   
        die("请输入8到15位密码");
    };

防止任意用户注册,并执行插入语句

 $sql1 = "SELECT id FROM user WHERE id=$id";
    $res1 = mysqli_query($link,$sql1);
    if(mysqli_num_rows($res1)){
        die("该用户名已被注册");
    }

    $sql2 = "INSERT INTO `user` (`username`, `id`, `password`) VALUES ('$username', '$id','$password')";
    mysqli_query($link,$sql2);
    echo("恭喜你:$username 注册成功");
    $link->close();

实现效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

接下来是要实现登陆

html方面基本与注册同理
php方面用select查询记录,结合mysqli_num_rows()函数判断记录数是0还是1

<?php
    header('Content-type:text/html;charset=utf-8');
    $link=mysqli_connect('localhost','root','','login');

    if ($link->connect_error) {
        die("连接错误: " . $link->connect_error);
    }

    $id = $_POST['id'];
    $password = $_POST['password'];

    if (is_numeric($id)){
        if (strlen($id)<8||strlen($id)>15){   
            die("请输入8到15位的账号");
        }
    }
    else{
        die("账号中只能由数字组成");
    }

    if (strlen($password)<8||strlen($password)>15){   
        die("请输入8到15位密码");
    };

    $sql="SELECT id, password FROM user WHERE id='$id' && password='$password'";
    $res=mysqli_query($link,$sql);
    $number=mysqli_num_rows($res);
    if($number){
        echo("登陆成功");
    }
    else{
        echo("账号或密码出错");
    };

拾遗

border-radius 设置圆角单位px,前提是有边框

text-decoration:none 去除超链接下划线

mysqli_num_rows 返回查询的记录数量

防止sql注入使用预编译PreparedStatement

使用转义字符函数,防止SQL注入

防止sql注入

addslashes()作用及使用

addslashes()通常用于防止sql注入,它可对通过get,post和cookie传递过来的参数的单引号和双引号已经null前加“\”进行转义

如:如变量$str=$_POST["str"];的值为:bb' or 1='1。通过addslashes()函数过滤后会变为:bb\' or 1=\'1

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huamanggg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值