zoukankan      html  css  js  c++  java
  • php用户登入与注销(cookie)

    登入界面

    <?php
        header('Content-type:text/html;charset=utf-8');   
        if(isset($_COOKIE['username']) && $_COOKIE['username']==='zeng'){
            exit('您已经登入了,请不要重新登入');
        }
    
        if(isset($_POST['submit'])){
            if(isset($_POST['username']) && isset($_POST['password']) && $_POST['username']=='zengguanling' && $_POST['password']=='123456' ){
                if(setcookie('username',$_POST['username'],  time()+3600)){
                    header('location:skip.php?url=index.php&info=登入成功!3秒后跳转到首面');
                }  else {
                    echo 'cookies设置失败';
                }
            }  else {
                header('location:skip.php?url=login.php&info=对不起,用户名活密码填写错误!3秒后跳转到登入页面');
            }
        }
    ?>
    <!DOCTYPE html>
    <html lang="zh-CN">
        <head>
            <meta charset="utf-8">
            <title>请登入</title>
        </head>
        <body>
            <form method="post" action="">
                姓名:<input type="text" name="username" />
                密码:<input type="password" name="password"/>
                <input type="submit" name="submit" value="登入"/>
            </form>
        </body>
    </html>

    跳转处理页面skip.php

    <?php
        if(!isset($_GET['url']) || !isset($_GET['info'])){
            exit();
        }
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <meta http-equiv="refresh" content="3,URL=<?php echo $_GET['url'] ?>"/>
            <title>正在跳转中...</title>
        </head>
        <body>
            <div><?php echo $_GET['info'] ?></div>
        </body>
    </html>

    登入首页index.php

    <?php
        header('Content-type:text/html;charset=utf-8');    
        if(isset($_COOKIE['username']) && $_COOKIE['username']==='zeng'){
            echo "您好!{$_COOKIE['username']},欢迎回来!";
            echo "<a href='logout.php'>注销</a>";
        }  else {
            echo "<a href='login.php'>请登入</a>";
        }
    ?>

    注销处理界面logout.php

    <?php
        header('Content-type:text/html;charset=utf-8');
        if(isset($_COOKIE['username']) && $_COOKIE['username']==='zeng'){
            if(setcookie('username',$_POST['username'],time()-3600)){
                header('location:skip.php?url=index.php&info=注销成功,正在跳转!');
            }else{
                header('location:skip.php?url=index.php&info=注销失败,请稍后重试!');
            }
        }
    ?>
  • 相关阅读:
    [loss]Triphard loss优雅的写法
    [Pytorch]Pytorch中tensor常用语法
    [pytorch]pytorch loss function 总结
    [Pytorch]Pytorch的tensor变量类型转换
    [Pytorch]Pytorch中图像的基本操作(TenCrop)
    caffe深度学习网络(.prototxt)在线可视化工具:Netscope Editor
    samba网络共享
    openwrt开发笔记三:uci移植及API调用
    openwrt开发笔记二:树莓派刷openwrt
    git跟踪忽略规则文件.gitignore
  • 原文地址:https://www.cnblogs.com/zgl-x/p/5847508.html
Copyright © 2011-2022 走看看