共计 1221 个字符,预计需要花费 4 分钟才能阅读完成。
前言
近期有群友私聊问我能不能给网页加上 访问密码
,要求只提供给 内部使用
,按理来说宝塔控制面板支持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>
');
} ?>
正文完
关注 “浮沉博客” 微信公众号获取更多内容
![post-qrcode](https://www.fuchenboke.cn/wp-content/uploads/2023/03/qrcode_for_gh_01f07ac60f9b_258.jpg)