PHP实现无数据库单页输入密码查看内容的方法

小小
2023-12-24 / 0 评论 / 36 阅读 / 正在检测是否收录...

PHP实现无数据库单页输入密码查看内容的方法
lqjjpnv5.png

方法
创建index.php文件,写入如下代码:

<?php 
header('Content-type:text/html;charset=utf-8');
$password = "123123"; // 这里是正确密码  
$p = "";  
if(isset($_COOKIE["isview"]) && $_COOKIE["isview"] == $password){  
$isview = true;  
}else{  
if(isset($_POST["pwd"])){  
if($_POST["pwd"] == $password){  
setcookie("isview",$_POST["pwd"],time()+3600*0.2);  
$isview = true;  
}else{  
$p = (empty($_POST["pwd"])) ? "需要密码才能查看,请输入密码。" : "密码不正确,请重新输入。";  
}  
}else{  
$isview = false;  
$p = "请输入密码查看";  
}  
}  
?>
<?php if($isview){  ?>
<!--这里是内容开头-->
我是内容
<!--这里是内容结尾-->
<?php }else{ ?>
<!DOCTYPE html>
<html>
<head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
   <title>网站监控登录</title>
   <link rel="stylesheet" href="//www.xiaoiv.com/admin/static/common/layui/css/layui.css">
<link rel="stylesheet" href="//www.xiaoiv.com/admin/css/login.css" media="all" />
   <script src="//www.xiaoiv.com/admin/static/common/layui/layui.js"></script>
   <style>
.login {
   height: 160px;
   width: 260px;
   padding: 20px;
   background: #fff;
   border-radius: 4px;
   position: absolute;
   left: 50%;
   top: 50%;
   margin: -150px 0 0 -150px;
   z-index: 99;
   border: 5px solid #eee;
}
   </style>
</head>
<div class="login">
   <h1>网站监控登录</h1>
   <form class="layui-form" method="post">
       <input type="hidden" name="dopost" value="login" />
       <div class="layui-form-item">
           <input class="layui-input" name="pwd" id="pwd" placeholder="密码" lay-verify="required" type="password" autocomplete="off">
       </div>
               <button class="layui-btn login_btn" lay-submit lay-filter="login">登录</button>
   </form>
</div>
   <script src="//www.xiaoiv.com/admin/js/md5.js"></script>
   <script>


       layui.use('form', function () {
           var form = layui.form,
               layer = layui.layer,
               $ = layui.jquery;


           layer.tips('欢迎来到XN-CMS后台管理!<br/>管理员请继续,非管理员请绕道!', '.layui-btn', {
               tips: [3, '#333'],
               time: 0
           });

           form.on('submit(login)', function (data) {
               //sessionStorage.isLgoin = 1; //模拟登录状态,实际使用时请删除掉
               // document.cookie="u_Cookie="+document.getElementById('user').value;
               document.cookie="p_Cookie="+md5(document.getElementById('pwd').value);
               layer.load({
                   shade: 0.5,
                   time: 0,
               });
               // setTimeout(function () {
               //     window.location.href = 'index.php';
               // },1000)

               return false;
           });
       });
   </script>
</div>
</body>
</html>
<?php } ?>
0

评论 (0)

取消