网站页面登录注册项目

<html>
    <!--登陆界面代码-->
    <head>
        <meta charset="utf8"/>
    </head>
    <div class="img">
        <img  src="./img/land.png" style="margin : 0 auto;"/>
    </div>
    <br/>
    <form action='land.php' method="POST">
        账号:&nbsp; &nbsp; <input type="text" name ='account' value=""/>
        <br/>
        <br/>
        密码:&nbsp;&nbsp; <input type="password" name="password" />
        <br/>
        <br/>
        <input type="submit" name="submit" value="登陆"/>&nbsp; &nbsp;&nbsp; &nbsp;
        <input type="button" name="rigester" value="注册" onclick="window.location.href='register.html'"/>
    </form>
</html>
<?php
//实现php 登陆功能
//并利用cookie技术实现七天免登录
$account = $_POST['account'] or die('账号提取失败');
$password = $_POST['password'] or die ('密码提取失败');
if(empty($account)||empty($password)){
    echo ('账号密码不能为空');
    header('Refresh:3,url=land.html');
    exit;
}
//操作数据库 
function meetError(){
    echo mysqli_error($conn);
    header('Refresh:3,url=land.html');
    exit;
}
$conn = mysqli_connect('localhost','root',980613) or die('数据库连接失败');
$sql = 'set names utf8';
mysqli_query($conn,$sql) or meetError();
$sql = 'use register';
mysqli_query($conn,$sql) or meetError();
//根据账号提取密码
$sql = "select password from info where account={$account}";
$res = mysqli_query($conn,$sql) or meetError();
//先把数据搞出来
$arr =array();
$arr = mysqli_fetch_row($res);  
if(mysqli_num_rows($res)!=1){
    echo "账号密码出错";
    header('Refresh:3,url=land.html');
    exit;
}else if($arr[0]==$password) {
    //成功登陆给浏览器设置cookie 让其七天免登陆
    setcookie('is_land','1',time()+7*24*3600);
    header('location:judge.php');
}else{
    echo "密码不正确";
    header('Refresh:3,url=land.html');
    exit;
}
mysqli_close($conn);
?>
<html>
    <!--注册功能的前端代码-->
    <head>
        <meta charset="utf8"/>
    </head>
    <p>账号注册</p>
    <br/>
    <form action="register.php" method="POST">
            账号:&nbsp; &nbsp; <input type="text" name ='account' value=""/>
            <br/>
            <br/>
            密码:&nbsp;&nbsp; <input type="password" name="password" />
            <br/>
            <input type="submit" name="submit" value="注册"/>
    </form>
</html>
<?php
/*
*实现注册功能的后端代码 
* 把register.html 中的数据存到数据库之中
*/
$account = $_POST['account'] or die("服务器错误 账号提取失败");
$password =$_POST['password'] or die ('服务器出错 密码提取失败');
//把数据放到已经建好的数据库之中 register 表名 info 
//封装一个函数 数据库操作遇到错误的时候调用
function meetError(){
    global $conn;
    $error = mysqli_error($conn);
    header('Refresh:3,url=register.html');
    exit;
}
$conn = mysqli_connect('localhost','root',980613) ;
echo mysqli_connect_error($conn);
$sql = 'set names utf8';
mysqli_query($conn,$sql) or meetError();
$sql='use register';
mysqli_query($conn,$sql) or meetError();
//先判断账号密码是否为空
if(empty($account)||empty($password)){
    echo "账号与密码不能为空";
    header('Refresh:3,url=register.html');
    exit;
}
//判断账号是否重复
$sql = "select id from info where account='{$account}';";
$res = mysqli_query($conn,$sql) or meetError();
if(mysqli_num_rows($res)!=0){
    echo '此账号已被注册';
    header('Refresh:3,url=register.html');
    exit;
}
//把账号与密码insert into 数据库
$sql = " insert into info (account,password)
         values('{$account}','{$password}')
";
$res = mysqli_query($conn,$sql);
if($res){
    echo "注册成功";
    header('Refresh:3,url = land.html');
    exit;
}else{
    echo "注册失败   ".mysqli_error($conn);
    header('Refresh:3 url = register.html');
}
mysqli_close($conn);
?>
<?php
//判断是否登陆成功 没有登陆过的会被退出来
$is_land = $_COOKIE['is_land'] or die('请登陆后访问!');
if($is_land=="1"){
//加载成功登陆后的界面
include_once "success.html";
}else{
    echo "请登录";
    header('Refresh:3,url=land.html');
    exit;
}
?>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值