Loading... ## 效果 ![3094341656.jpg][1] ## 使用方法 在主题目录下添加文件MkEncrypt.php ```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() + 3600*24*1, '/'); return; } ?> <style type="text/css"> *{font-family:"Microsoft Yahei",微软雅黑,"Helvetica Neue",Helvetica,"Hiragino Sans GB","WenQuanYi Micro Hei",sans-serif;box-sizing:border-box;margin:0px;padding:0px;font-size:14px;-webkit-transition:.2s;-moz-transition:.2s;-ms-transition:.2s;-o-transition:.2s;transition:.2s} html,body{width:100%;height:100%} body{background-color:#F4F6F9;color:#768093} input,button{font-size:1em;border-radius:3px;-webkit-appearance:none} input{width:100%;padding:5px;box-sizing:border-box;border:1px solid #e5e9ef;background-color:#f4f5f7;resize:vertical} input:focus{background-color:#fff;outline:none} button{border:0;background:#6abd09;color:#fff;cursor:pointer;opacity:1;user-select:none} button:hover,button:focus{opacity:.9} button:active{opacity:1} .main{width:100%;max-width:500px;height:300px;padding:30px;background-color:#fff;border-radius:2px;box-shadow:0 10px 60px 0 rgba(29,29,31,0.09);transition:all .12s ease-out;position:absolute;left:0;top:0;bottom:0;right:0;margin:100px 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 #ebebeb;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-tip{font-weight:normal;font-size:26px;text-align:center;margin:25px auto} #pw-error {color: red;margin-top: 15px;margin-bottom: -20px;} .return-home{text-decoration:none;color:#b1b1b1;font-size:16px} .return-home:hover{color:#1E9FFF;letter-spacing:5px} </style> <div class="main"> <form action="" method="post" class="mk-side-form"> <h2 class="pw-tip">该页面已被加密</h2> <input type="password" name="pagepwd" placeholder="请输入访问密码查看" required><button type="submit">提交</button> <?php if($postpwd): ?> <p id="pw-error">emmm...密码不对哦~再想想吧!</p> <script>setTimeout(function() {document.getElementById("pw-error").style.display = "none"}, 2000);</script> <?php endif; ?> </form> <a href="https://www.ifking.cn/go/Lw==.html" target="_blank" class="return-home" title="点击回到网站首页">- 返回首页 - </a> </div> <?php exit(); } ``` 添加文件passwd.php ```php <?php /** * 密码加密 * * @package custom */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; require_once('MkEncrypt.php'); $this->need('component/header.php'); $passwd = $this->fields->passwd; ?> <style type="text/css"> </style> <!-- aside --> <?php $this->need('component/aside.php'); ?> <!-- / aside --> <!-- <div id="content" class="app-content"> --> <main class="app-content-body <?php Content::returnPageAnimateClass($this); ?>"> <div class="hbox hbox-auto-xs hbox-auto-sm"> <div class="wrapper-md"> <div class="tab-container"> <div class="tab-content"> <?php MkEncrypt($passwd);//设置密码?> <?php echo Content::postContent($this,$this->user->hasLogin()); ?> <!--评论--> <?php $this->need('component/comments.php') ?> </div> </div> </div> <!--首页右侧栏--> <?php $this->need('component/sidebar.php') ?> </div> <!-- /content --> </main> <!-- footer --> <?php $this->need('component/footer.php'); ?> <!-- / footer --> ``` 开始使用 创建页面时自定义模板选择密码加密,添加自定义字段passwd,值为你想要设置的密码 ## 引用 > - MKEncrypt作者为mengkun:https://mkblog.cn/1692/ > - 自定义模板借鉴了Handsome的部分代码 [1]: https://i.loli.net/2019/08/10/FtUEsMkN4yQpcGO.jpg 最后修改:2020 年 02 月 23 日 10 : 19 PM © 允许规范转载 赞赏 赏包辣条吧 ×Close 赞赏作者 扫一扫支付 支付宝支付 微信支付