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

55gY 2,860 0

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

使用方法

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

PHP
  1. require_once('MkEncrypt.php');
  2. MkEncrypt('密码');
  3. //你的代码
复制 文本 高亮

MkEncrypt.php

PHP
  1. <?php
  2. /********************************************
  3. * 使用方法:
  4. *
  5. * 1、将本段代码保存为 MkEncrypt.php
  6. *
  7. * 2、在要加密的页面前面引入这个 php 文件
  8. * require_once('MkEncrypt.php');
  9. *
  10. * 3、设置页面访问密码
  11. * MkEncrypt('页面密码');
  12. *
  13. ********************************************/
  14. // 密码 Cookie 加密
  15. if(!defined('MK_ENCRYPT_SALT'))
  16. define('MK_ENCRYPT_SALT', 'Kgs$JC!V');
  17. /**
  18. * 设置访问密码
  19. *
  20. * @param $password 访问密码
  21. * @param $pageid 页面唯一 ID 值,用于区分同一网站的不同加密页面
  22. */
  23. function MkEncrypt($password, $pageid = 'default') {
  24. $pageid = md5($pageid);
  25. $md5pw = md5(md5($password).MK_ENCRYPT_SALT);
  26. $postpwd = isset($_POST['pagepwd']) ? addslashes(trim($_POST['pagepwd'])) : '';
  27. $cookiepwd = isset($_COOKIE['mk_encrypt_'.$pageid]) ? addslashes(trim($_COOKIE['mk_encrypt_'.$pageid])) : '';
  28. if($cookiepwd == $md5pw) return; // Cookie密码验证正确
  29. if($postpwd == $password) { // 提交的密码正确
  30. setcookie('mk_encrypt_' . $pageid, $md5pw, time() + 600, '/');
  31. return;
  32. }
  33. ?>
  34. <html>
  35. <head>
  36. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  37. <meta charset="UTF-8">
  38. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  39. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  40. <meta http-equiv= "Pragma" content= "no-cache" />
  41. <meta http-equiv= "Cache-Control" content= "no-cache" />
  42. <meta http-equiv= "Expires" content= "0" />
  43. <meta name="renderer" content="webkit">
  44. <meta name="keywords" content="55gY|图片" />
  45. <meta name="description" content="55gY|图片" />
  46. <meta name="author" content="55gY|图片(55gy.cn)" />
  47. <meta name="copyright" content="55gY|图片(55gy.cn)" />
  48. <link rel="icon" href="https://55gy.cn/wp-content/uploads/2019/03/cropped-20190329_111020_86-32x32.png" sizes="32x32">
  49. <link rel="icon" href="https://55gy.cn/wp-content/uploads/2019/03/cropped-20190329_111020_86-192x192.png" sizes="192x192">
  50. <link rel="apple-touch-icon-precomposed" href="https://55gy.cn/wp-content/uploads/2019/03/cropped-20190329_111020_86-180x180.png">
  51. <meta name="msapplication-TileImage" content="https://55gy.cn/wp-content/uploads/2019/03/cropped-20190329_111020_86-270x270.png">
  52. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  53. <title>55gY|图片</title>
  54. <style type="text/css">
  55. body,html{margin:0;padding:0}
  56. 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}
  57. audio:hover{opacity:1}
  58. .wall{position:absolute;top:0;left:0;bottom:0;right:0}
  59. 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}
  60. 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}
  61. 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}
  62. 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}
  63. @-webkit-keyframes cc{from{background-position:0 0;transform:translateY(10px)}
  64. to{background-position:600% 0}
  65. }
  66. @-o-keyframes cc{from{background-position:0 0;transform:translateY(10px)}
  67. to{background-position:600% 0}
  68. }
  69. @-moz-keyframes cc{from{background-position:0 0;transform:translateY(10px)}
  70. to{background-position:600% 0}
  71. }
  72. @keyframes cc{0%{background-position:0 0}
  73. 100%{background-position:600% 0}
  74. }
  75. @keyframes da{0%{background-position:0 0}
  76. 100%{background-position:0 600%}
  77. }
  78. @-webkit-keyframes da{0%{background-position:0 0}
  79. 100%{background-position:0 600%}
  80. }
  81. @-moz-keyframes da{0%{background-position:0 0}
  82. 100%{background-position:0 600%}
  83. }
  84. @-ms-keyframes da{0%{background-position:0 0}
  85. 100%{background-position:0 600%}
  86. }
  87. button,input{font-size:1em;border-radius:3px;-webkit-appearance:none}
  88. input{width:100%;padding:5px;box-sizing:border-box;border:1px solid #0000;background-color:#0000;resize:vertical}
  89. input:focus{background-color:#0000;outline:0;border:1px solid #fff}
  90. button{border:0;background:#cecece5e;color:#fff;cursor:pointer;opacity:1;user-select:none}
  91. .return-home:hover,button:focus,button:hover{opacity:.9}
  92. button:active{opacity:1}
  93. .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}
  94. .alert{width:80px}
  95. .mk-side-form{margin-bottom:28px}
  96. .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}
  97. .mk-side-form button{position:relative;overflow:visible;width:23%;height:37px;border-radius:0 2px 2px 0;text-transform:uppercase}
  98. #pw-error{color:red;margin-top:15px;margin-bottom:-20px}
  99. .return-home{text-decoration:none;color:#b1b1b1;font-size:16px}
  100.  
  101. </style>
  102. </head>
  103. <body>
  104. <audio id="backgroud-music" controls="controls" autoplay="autoplay" loop="loop">
  105. <source src="Windy Hill.mp3">
  106. </audio>
  107. <div id="background" class="wall"></div>
  108. <div id="midground" class="wall"></div>
  109. <div id="foreground" class="wall"></div>
  110. <div id="top" class="wall"></div>
  111. <div class="main">
  112. <form action="" method="post" class="mk-side-form">
  113. <input type="password" name="pagepwd" placeholder="天王盖地虎" autocomplete="new-password"><button type="submit">提交</button>
  114. <?php if($postpwd): ?>
  115. <script>alert("有内鬼,停止交易");</script>
  116. <?php endif; ?>
  117. </form>
  118. <a href="/" class="return-home" title="点击回到网站首页">- 返回首页 - </a>
  119. </div>
  120. </body>
  121. </html>
  122. <?php
  123. exit();
  124. }
复制 文本 高亮

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

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