使用PHP代码实现网页加密

0.0/0人
免费

更新时间:2025-01-27 10:46:39

所属分类:网站特效

评论回复:0

 

暂无演示 下载权限

前言

近期有群友私聊问我能不能给网页加上 访问密码,要求只提供给内部使用,按理来说宝塔控制面板支持BasicAuth 认证,实现密码访问,但效果太单一,今天就给大家分享一段 PHP 代码轻松实现网页加密访问

实现

代码为 PHP 格式,密码在第 3 行 ['password'] == '123' 此处 123 即为密码,第 7 行 - 第 32 行为密码拦截显示端 支持 css,可自定义修改

<?php
 session_start();
 if (isset($_POST['password']) && $_POST['password'] == '123'){$_SESSION['ok'] = 1;
 header('location:?');
}
 if (!isset($_SESSION['ok'])) {
 exit('<style type="text/css">
.container{overflow:hidden;margin:4px auto;}
.container .content{max-width: 100%;width: 600px;margin: 0 auto;overflow: hidden;}
.new-content{height: 100%;}
.new-content .new-pw{position:relative;overflow:hidden;margin-top:13px;padding:15px;height: 10%;background:rgb(247, 247, 247);}
.new-title{position: relative;height: 45px;border-bottom: 1px solid #5298ff;text-indent: 21px;font-size: 16px;line-height: 35px;font-weight: 600;color: #2196f3;}
.new-title:after{position:absolute;top:8px;left:0;width:0;height:17px;border:1.5px solid #5298ff;border-radius:9px;content:" ";}
</style>

<div class="container">
 <div class="content">
  <div class="new-content">
   <div class="new-pw">
    <div class="new-title"> 访问已被拦截请输入密码进行验证 </div>
   <div class="new-pws">
    <center style="margin-top: 8px;">
       <form method="post">
        密码:<input type="password" name="password" />
             <input type="submit" value="确定" />
       </form>
    </center>
   </div>
  </div>
 </div>
</div>
</div>
');
} ?>
首页 导航 会员 客服
客服QQ 客服邮箱 TOP