PHP页面输入密码才能访问加密代码

添加在页面顶部即可,内容是或者要显示的PHP代码是写在密码提示代码下面。
代码一: (cookie六十秒就过期需要重新输入密码)
<?php
$$password = "123";//密码
$$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){?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>使用后请关闭!</title>
<style type="text/css">
body{background:none;}
.passport{width:400px;position:absolute;left:50%;
top:50%;margin-left:-200px;margin-top:-55px;font-size:18px;text-align:center;line-height:30px;/*color:red;*/}
</style>
</head>
<body>
<div class="passport">
显示内容
</div>
</body>
</html>
<?php }else{?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>此页面加密请输入密码!</title>
<style type="text/css">
body{background:none;}
.passport{border:1px solid red;background-color:#FFFFCC;
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;}
</style>
</head>
<body>
<div class="passport"><div style="padding-top:20px;">
<form action="" method="post" style="margin:0px;">
password:<input type="password" name="pwd" /> <input type="submit" value="OK" />
</form>
<?php echo $$p;?>
</div></div>
</body>
</html>
<?php }?>
代码二
<?php
$$adminkey = "123";/*设置密码*/
session_start();
if(@$$_POST['password'] == $$adminkey){
$$_SESSION['login'] = md5($$adminkey);
}
if($$_SERVER['QUERY_STRING'] == "logout"){
$$_SESSION['login'] = "";
header("location: " . $$_SERVER['PHP_SELF']);
exit();
}
$$html_login = <<<EOF
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
div{text-align:center; margin:0 auto;}
#loginform{width:230px;height:100px;background-color:#ffffff;box-shadow: 2px 2px 10px 1px #403f3f;}
</style>
</head>
<body>
<div id="loginform">
<div style="text-align:center; margin:260px auto 0px;">
<form action="" method="post">密码<input type="password" name="password" style="width:120px; margin-top: 35px;">
<input type="submit" value="登录" style="margin-left: 5px;">
</form>
</div>
</div>
</body>
</html>
EOF;
if(@$$_SESSION['login'] != md5($$adminkey)){
exit($$html_login);
}
?>
这里加上要显示的内容文字或者代码。

+