PHP为任意页面设置访问密码

55gY 2,727 0

转载:https://mkblog.cn/1692/
预览地址:https://55gy.cn/img/

使用方法

1、将代码保存为 MkEncrypt.php
2、在要加密的页面前面引入这个 php 文件

require_once('MkEncrypt.php');
MkEncrypt('密码');
//你的代码

MkEncrypt.php

<?php
/********************************************
 * 使用方法:
 * 
 * 1、将本段代码保存为 MkEncrypt.php
 * 
 * 2、在要加密的页面前面引入这个 php 文件   
 *  require_once('MkEncrypt.php');
 * 
 * 3、设置页面访问密码 
 *  MkEncrypt('页面密码');
 * 
********************************************/
// 密码 Cookie 加密
if(!defined('MK_ENCRYPT_SALT'))
    define('MK_ENCRYPT_SALT', 'Kgs$JC!V');
/**
 * 设置访问密码
 * 
 * @param $password  访问密码
 * @param $pageid    页面唯一 ID 值,用于区分同一网站的不同加密页面
 */
function MkEncrypt($password, $pageid = 'default') {
    $pageid     = md5($pageid);
    $md5pw      = md5(md5($password).MK_ENCRYPT_SALT);
    $postpwd    = isset($_POST['pagepwd']) ? addslashes(trim($_POST['pagepwd'])) : '';
    $cookiepwd  = isset($_COOKIE['mk_encrypt_'.$pageid]) ? addslashes(trim($_COOKIE['mk_encrypt_'.$pageid])) : '';
    if($cookiepwd == $md5pw) return;    // Cookie密码验证正确
    if($postpwd == $password) {         // 提交的密码正确
        setcookie('mk_encrypt_' . $pageid, $md5pw, time() + 600, '/');
        return;
    }
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta http-equiv= "Pragma"   content= "no-cache" /> 
    <meta http-equiv= "Cache-Control"   content= "no-cache" /> 
    <meta http-equiv= "Expires"   content= "0" /> 
    <meta name="renderer" content="webkit">
    <meta name="keywords" content="55gY|图片" />
	<meta name="description" content="55gY|图片" />
	<meta name="author" content="55gY|图片(55gy.cn)" />
    <meta name="copyright" content="55gY|图片(55gy.cn)" />
    <link rel="icon" href="https://55gy.cn/wp-content/uploads/2019/03/cropped-20190329_111020_86-32x32.png" sizes="32x32">
    <link rel="icon" href="https://55gy.cn/wp-content/uploads/2019/03/cropped-20190329_111020_86-192x192.png" sizes="192x192">
    <link rel="apple-touch-icon-precomposed" href="https://55gy.cn/wp-content/uploads/2019/03/cropped-20190329_111020_86-180x180.png">
    <meta name="msapplication-TileImage" content="https://55gy.cn/wp-content/uploads/2019/03/cropped-20190329_111020_86-270x270.png">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>55gY|图片</title>
    <style type="text/css">
    body,html{margin:0;padding:0}
audio{z-index:5;position:absolute;bottom:0;opacity:.1;-webkit-transition:all 2s;-moz-transition:all 2s;-ms-transition:all 2s;-o-transition:all 2s;transition:all 2s}
audio:hover{opacity:1}
.wall{position:absolute;top:0;left:0;bottom:0;right:0}
div#background{background:url(https://s5.mogucdn.com/mlcdn/fe720b/191127_7519e2d54klg44h2d35fjleg3d6c2_3430x1462.jpg) no-repeat;-webkit-animation:dd 100s linear infinite;-moz-animation:dd 100s linear infinite;-o-animation:dd 100s linear infinite;animation:dd 100s linear infinite;background-size:cover}
div#midground{background:url(https://s5.mogucdn.com/mlcdn/fe720b/191127_8aa686ieib6k134748ie5928i5f57_500x500.png);z-index:1;-webkit-animation:cc 100s linear infinite;-moz-animation:cc 100s linear infinite;-o-animation:cc 100s linear infinite;animation:cc 100s linear infinite}
div#foreground{background:url(https://s11.mogucdn.com/mlcdn/fe720b/191127_88j635d9hal691hk7l8j3ch59gga9_500x500.png);z-index:2;-webkit-animation:cc 153s linear infinite;-o-animation:cc 153s linear infinite;-moz-animation:cc 153s linear infinite;animation:cc 153s linear infinite}
div#top{background:url(https://s5.mogucdn.com/mlcdn/fe720b/191127_8aa686ieib6k134748ie5928i5f57_500x500.png);z-index:4;-webkit-animation:dd 100s linear infinite;-o-animation:dd 100s linear infinite;animation:da 100s linear infinite}
@-webkit-keyframes cc{from{background-position:0 0;transform:translateY(10px)}
to{background-position:600% 0}
}
@-o-keyframes cc{from{background-position:0 0;transform:translateY(10px)}
to{background-position:600% 0}
}
@-moz-keyframes cc{from{background-position:0 0;transform:translateY(10px)}
to{background-position:600% 0}
}
@keyframes cc{0%{background-position:0 0}
100%{background-position:600% 0}
}
@keyframes da{0%{background-position:0 0}
100%{background-position:0 600%}
}
@-webkit-keyframes da{0%{background-position:0 0}
100%{background-position:0 600%}
}
@-moz-keyframes da{0%{background-position:0 0}
100%{background-position:0 600%}
}
@-ms-keyframes da{0%{background-position:0 0}
100%{background-position:0 600%}
}
button,input{font-size:1em;border-radius:3px;-webkit-appearance:none}
input{width:100%;padding:5px;box-sizing:border-box;border:1px solid #0000;background-color:#0000;resize:vertical}
input:focus{background-color:#0000;outline:0;border:1px solid #fff}
button{border:0;background:#cecece5e;color:#fff;cursor:pointer;opacity:1;user-select:none}
.return-home:hover,button:focus,button:hover{opacity:.9}
button:active{opacity:1}
.main{z-index:999;width:100%;max-width:300px;height:80px;padding:30px;background-color:#0000001f;border-radius:2px;box-shadow:0 10px 60px 0 rgba(29,29,31,.09);transition:all .12s ease-out;position:absolute;left:0;top:0;bottom:0;right:0;margin:auto;text-align:center}
.alert{width:80px}
.mk-side-form{margin-bottom:28px}
.mk-side-form input{float:left;padding:2px 10px;width:77%;height:37px;border:1px solid #0000;border-right-color:transparent;border-radius:2px 0 0 2px;line-height:37px}
.mk-side-form button{position:relative;overflow:visible;width:23%;height:37px;border-radius:0 2px 2px 0;text-transform:uppercase}
#pw-error{color:red;margin-top:15px;margin-bottom:-20px}
.return-home{text-decoration:none;color:#b1b1b1;font-size:16px}

    </style>
</head>
<body>
<audio id="backgroud-music" controls="controls" autoplay="autoplay" loop="loop">
    <source src="Windy Hill.mp3">
</audio>
<div id="background" class="wall"></div>
<div id="midground" class="wall"></div>
<div id="foreground" class="wall"></div>
<div id="top" class="wall"></div>
    <div class="main">
        <form action="" method="post" class="mk-side-form">
            <input type="password" name="pagepwd" placeholder="天王盖地虎" autocomplete="new-password"><button type="submit">提交</button>
            <?php if($postpwd): ?>
            <script>alert("有内鬼,停止交易");</script>
            <?php endif; ?>
        </form>
        <a href="/" class="return-home" title="点击回到网站首页">- 返回首页 - </a>
    </div>
</body>
</html>
<?php
    exit();
}

本站资源来自互联网收集,仅供用于学习和交流,请勿用于商业用途。如有侵权、不妥之处,请联系站长并出示版权证明以便删除。敬请谅解!

发表评论 取消回复
表情 图片 链接 代码