前言
喜讯:&(蛆音娘_大笑) 我的宝贝快要出生了
所以我在博客中加了个相册的单页 用来存放我的大宝贝和小宝贝的生活点滴,但是为了家人们的信息安全 我需要设置个只有我们知道的密码进行访问
代码
<?php
//密码访问本页面
$password = "20200106";//密码
$p = "";
if(isset($_COOKIE["isview"]) and $_COOKIE["isview"] == $password){
$isview = true;
}else{
if(isset($_POST["pwd"])){
if($_POST["pwd"] == $password){
setcookie("isview",$_POST["pwd"],time()+60);$isview = true;}else{$p = (empty($_POST["pwd"])) ?"请输入密码." : "<div style=\"color:#F00;\">密码不正确.</div>";}
}else{
$isview = false;$p = "此页面加密访问请输入密码。";
}}?>
<?php if($isview){?>
<!-- html模板加载开始 -->
<!DOCTYPE HTML>
<html>
输入密码后正常显示的内容
</html>
<!-- html模板加载结束 -->
<?php }else{?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title><?php echo $p;?>!</title>
<style type="text/css">
body{background-image: url(https://cdn.jsdelivr.net/gh/WHBLeer/Gallery@master/img/20210128092033.jfif);}
.passport{background-color:rgba(255, 255, 255, 0.5);width:400px;height:100px;position:absolute;left:49.9%;top:49.9%;margin-left:-200px;margin-top:-55px;font-size:14px;text-align:center;line-height:30px;color:#746A6A;}
input {padding: 7px;text-align: center;border-radius: 5px;}
.tips {background-color:rgba(255, 0, 0, 0.3);color: #fff;text-align: center;padding: 2px 16px;font-size: 15px;}
</style>
</head>
<body>
<div class="passport">
<div style="padding-top:20px;">
<form action="" method="post" style="margin:0px;">
<input type="password" name="pwd" />
<input type="submit" value="确定" />
</form>
<span class="tips"><?php echo $p;?></span>
</div>
</div>
</body>
</html>
<?php }?>
次页面适用于所有php加载html的页面
评论 (0)