用http协议自带的加密方式有一个问题 就是 部分浏览 会不弹出密码输入框 直接401错误,而且每次打开都要输入一次密码。
本来不打算改动任何源码,只修改伪静态和首页顺序的,后来发现比较麻烦,奔着从简的原则。 决定还是改动一下index.php
在index.php中增加一行 include
header('Content-Type:text/html;charset=utf-8');
//增加密码判断 就是在index中添加下面这行
include "inc_index_psw.php";
新建文件 inc_index_psw.php 用于输入账户密码和检查cookie,代码比较简单
<?php
//跳过检查 通过 浏览器agent 这样在部分浏览器 或者反向代理可以自定agent的时候 跳过检查
$My_agent = $_SERVER['HTTP_USER_AGENT'];
// 先判断
if(strpos($My_agent,'mirror') ==false ){
//判断是qq或者微信打开的嘛
$My_agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($My_agent, 'QQ/')||strpos($My_agent, 'MicroMessenger')!==false){
html_browser();
die;
}
//获取登录状态
$my_is_logined=0;
if(isset($_COOKIE['my_is_logined']) ){
$my_is_logined=(int)$_COOKIE['my_is_logined'];
}
// 未登录
if($my_is_logined!=1){
//开始判断和验证登录
$my_chk_login=0;
if(isset($_POST['my_chk_login']) ){
$my_chk_login=(int)$_POST['my_chk_login'];
}
if($my_chk_login==1){
//验证登录信息和密码
if(trim($_POST['my_psw'])=="admin" || trim($_POST['my_psw'])=="123456" || trim($_POST['my_psw'])=="123" || trim($_POST['my_psw'])=="abc"){
//登录成功
setcookie('my_is_logined','1',time()+365*24*60*60,'/'); //一年有效
die ("<script language=JavaScript> location.replace(location.href);</script>");
}else{
die("<script>alert('密码错误');history.go(-1)</script>");
}
}else{
//输出登录界面
html_login();
}
die;
}
}
function html_browser(){
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>使用浏览器打开</title>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta name="format-detection" content="telephone=no">
<meta content="false" name="twcClient" id="twcClient">
<meta name="aplus-touch" content="1">
<style>
body,html{width:100%;height:100%}
*{margin:0;padding:0}
body{background-color:#fff}
#browser img{
width:50px;
}
#browser{
margin: 0px 10px;
text-align:center;
}
#contens{
font-weight: bold;
margin:-285px 0px 10px;
text-align:center;
font-size:20px;
margin-bottom: 125px;
}
.top-bar-guidance{font-size:15px;color:#fff;height:60%;line-height:1.8;padding-left:20px;padding-top:20px;background:url(//gw.alicdn.com/tfs/TB1eSZaNFXXXXb.XXXXXXXXXXXX-750-234.png) center top/contain no-repeat}
.top-bar-guidance .icon-safari{width:25px;height:25px;vertical-align:middle;margin:0 .2em}
.app-download-tip{margin:0 auto;width:290px;text-align:center;font-size:15px;color:#2466f4;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAcAQMAAACak0ePAAAABlBMVEUAAAAdYfh+GakkAAAAAXRSTlMAQObYZgAAAA5JREFUCNdjwA8acEkAAAy4AIE4hQq/AAAAAElFTkSuQmCC) left center/auto 15px repeat-x}
.app-download-tip .guidance-desc{background-color:#fff;padding:0 5px}
.app-download-btn{display:block;width:214px;height:40px;line-height:40px;margin:18px auto 0 auto;text-align:center;font-size:18px;color:#2466f4;border-radius:20px;border:.5px #2466f4 solid;text-decoration:none}
</style>
</head>
<body>
<div class="top-bar-guidance">
<p>点击右上角<img src="//gw.alicdn.com/tfs/TB1xwiUNpXXXXaIXXXXXXXXXXXX-55-55.png" class="icon-safari"> <span id="openm">Safari打开</span></p>
<p>可以继续浏览本站哦~</p>
</div>
<a style="display: none;" href="" id="vurl" rel="noreferrer"></a>
<div id="browser">
<p>避免微信和QQ屏蔽本站网址,请理解支持!</p>
</div>
<div class="app-download-tip">
<span class="guidance-desc">点击右上角或复制网址自行打开</span>
</div>
<link href="/static/layui/css/modules/layer/default/layer.css" rel="stylesheet" type="text/css" />
<script src="/static/js/jquery.js"></script>
<script src="/static/js/jquery.clipboard.js"></script>
<script src="/static/layui/lay/modules/layer.js"></script>
<a data-clipboard-text="<?php
echo curPageURL();
?>" class="app-download-btn">点此复制本站网址</a>
<script type="text/javascript">
new ClipboardJS(".app-download-btn");
$(".app-download-btn").click(function() {
layer.tips("复制成功,么么哒", ".app-download-btn", {
tips: [3, "rgb(38,111,250)"],
time:500
});})
</script>
<script>
function openu(u){
document.getElementById("vurl").href= u;
document.getElementById("vurl").click();
}
var url = window.location.href;
if(navigator.userAgent.indexOf("QQ/")> -1){
openu("ucbrowser://"+url);
openu("mttbrowser://url="+url);
openu("baiduboxapp://browse?url="+url);
openu("googlechrome://browse?url="+url);
openu("mibrowser:"+url);
openu("taobao://"+url.split("://")[1]);
openu("alipays://platformapi/startapp?appId=20000067&url="+url);
$("html").on("click",function(){
openu("ucbrowser://"+url);
openu("mttbrowser://url="+url);
openu("baiduboxapp://browse?url="+url);
openu("googlechrome://browse?url="+url);
openu("mibrowser:"+url);
openu("taobao://"+url.split("://")[1]);
openu("alipays://platformapi/startapp?appId=20000067&url="+url);
});
}else if(navigator.userAgent.indexOf("MicroMessenger") > -1){
if(navigator.userAgent.indexOf("Android") > -1){
var iframe = document.createElement("iframe");
iframe.style.display = "none";
document.body.appendChild(iframe);
}else{
}
}
</script>
</body>
</html>
<?php
}
// 说明:获取完整URL
function curPageURL()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on")
{
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
}
else
{
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
function html_login(){
?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>访问权限确认 </title>
<link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
background: #494A5F;
font-weight: 500;
font-family: "Microsoft YaHei","宋体","Segoe UI", "Lucida Grande", Helvetica, Arial,sans-serif, FreeSans, Arimo;
}
#container {
margin: 0 auto;
}
div.search {padding: 30px 0;}
form {
position: relative;
width: 300px;
margin: 0 auto;
}
input, button {
border: none;
outline: none;
}
input {
width: 100%;
height: 42px;
padding-left: 13px;
}
button {
height: 42px;
width: 42px;
cursor: pointer;
position: absolute;
}
/*搜索框6*/
.bar6 {}
.bar6 input {
border: 2px solid #c5464a;
border-radius: 5px;
background: #CCC;
top: 0;
right: 0;
}
.bar6 button {
background: #c5464a;
border-radius: 0 5px 5px 0;
width: 60px;
top: 0;
right: 0;
}
.bar6 button:before {
content: "登录";
font-size: 13px;
color: #F9F0DA;
}
</style>
</head>
<body>
<div id="container">
<div class="search bar6">
<form action="" method="POST" id="myform">
<input type="hidden" name="my_chk_login" value="1">
<input type="text" name="my_psw" placeholder="请输入密码a开头英文单词...">
<button type="submit"></button>
</form>
</div>
</div>
</body>
</html>
<?php
}
?>
补充伪静态规则,如后台地址修改过 这里有也改动一下
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^/api.php(.*)$ /api.php?s=$1 last;
rewrite ^/admin.php(.*)$ /admin.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
完善一下,加上QQ和微信防止内部打开
<?php
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($agent, 'QQ/')||strpos($agent, 'MicroMessenger')!==false){
html_browser();
die;
}
$my_is_logined=0;
if(isset($_COOKIE['my_is_logined']) ){
$my_is_logined=(int)$_COOKIE['my_is_logined'];
}
if($my_is_logined!=1){
//开始判断和验证登录
$my_chk_login=0;
if(isset($_POST['my_chk_login']) ){
$my_chk_login=(int)$_POST['my_chk_login'];
}
if($my_chk_login==1){
//判断密码
if(trim($_POST['my_psw'])=="admin"){
//登录成功
setcookie('my_is_logined','1',time()+365*24*60*60,'/'); //一年有效
die ("<script language=JavaScript> location.replace(location.href);</script>");
}else{
die("<script>alert('密码错误');history.go(-1)</script>");
}
}else{
//输出登录界面
?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>访问权限确认</title>
<link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
background: #494A5F;
font-weight: 500;
font-family: "Microsoft YaHei","宋体","Segoe UI", "Lucida Grande", Helvetica, Arial,sans-serif, FreeSans, Arimo;
}
#container {
margin: 0 auto;
}
div.search {padding: 30px 0;}
form {
position: relative;
width: 300px;
margin: 0 auto;
}
input, button {
border: none;
outline: none;
}
input {
width: 100%;
height: 42px;
padding-left: 13px;
}
button {
height: 42px;
width: 42px;
cursor: pointer;
position: absolute;
}
/*搜索框6*/
.bar6 {}
.bar6 input {
border: 2px solid #c5464a;
border-radius: 5px;
background: #CCC;
top: 0;
right: 0;
}
.bar6 button {
background: #c5464a;
border-radius: 0 5px 5px 0;
width: 60px;
top: 0;
right: 0;
}
.bar6 button:before {
content: "登录";
font-size: 13px;
color: #F9F0DA;
}
</style>
</head>
<body>
<div id="container">
<div class="search bar6">
<form action="" method="POST" id="myform">
<input type="hidden" name="my_chk_login" value="1">
<input type="text" name="my_psw" placeholder="请输入密码a开头英文单词...">
<button type="submit"></button>
</form>
</div>
</div>
</body>
</html>
<?php
}
die;
}
function html_browser(){
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>使用浏览器打开</title>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta name="format-detection" content="telephone=no">
<meta content="false" name="twcClient" id="twcClient">
<meta name="aplus-touch" content="1">
<style>
body,html{width:100%;height:100%}
*{margin:0;padding:0}
body{background-color:#fff}
#browser img{
width:50px;
}
#browser{
margin: 0px 10px;
text-align:center;
}
#contens{
font-weight: bold;
margin:-285px 0px 10px;
text-align:center;
font-size:20px;
margin-bottom: 125px;
}
.top-bar-guidance{font-size:15px;color:#fff;height:60%;line-height:1.8;padding-left:20px;padding-top:20px;background:url(//gw.alicdn.com/tfs/TB1eSZaNFXXXXb.XXXXXXXXXXXX-750-234.png) center top/contain no-repeat}
.top-bar-guidance .icon-safari{width:25px;height:25px;vertical-align:middle;margin:0 .2em}
.app-download-tip{margin:0 auto;width:290px;text-align:center;font-size:15px;color:#2466f4;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAcAQMAAACak0ePAAAABlBMVEUAAAAdYfh+GakkAAAAAXRSTlMAQObYZgAAAA5JREFUCNdjwA8acEkAAAy4AIE4hQq/AAAAAElFTkSuQmCC) left center/auto 15px repeat-x}
.app-download-tip .guidance-desc{background-color:#fff;padding:0 5px}
.app-download-btn{display:block;width:214px;height:40px;line-height:40px;margin:18px auto 0 auto;text-align:center;font-size:18px;color:#2466f4;border-radius:20px;border:.5px #2466f4 solid;text-decoration:none}
</style>
</head>
<body>
<div class="top-bar-guidance">
<p>点击右上角<img src="//gw.alicdn.com/tfs/TB1xwiUNpXXXXaIXXXXXXXXXXXX-55-55.png" class="icon-safari"> <span id="openm">Safari打开</span></p>
<p>可以继续浏览本站哦~</p>
</div>
<a style="display: none;" href="" id="vurl" rel="noreferrer"></a>
<div id="browser">
<p>避免微信和QQ屏蔽本站网址,请理解支持!</p>
</div>
<div class="app-download-tip">
<span class="guidance-desc">点击右上角或复制网址自行打开</span>
</div>
<link href="/static/layui/css/modules/layer/default/layer.css" rel="stylesheet" type="text/css" />
<script src="/static/js/jquery.js"></script>
<script src="/static/js/jquery.clipboard.js"></script>
<script src="/static/layui/lay/modules/layer.js"></script>
<a data-clipboard-text="<?php
echo curPageURL();
?>" class="app-download-btn">点此复制本站网址</a>
<script type="text/javascript">
new ClipboardJS(".app-download-btn");
$(".app-download-btn").click(function() {
layer.tips("复制成功,么么哒", ".app-download-btn", {
tips: [3, "rgb(38,111,250)"],
time:500
});})
</script>
<script>
function openu(u){
document.getElementById("vurl").href= u;
document.getElementById("vurl").click();
}
var url = window.location.href;
if(navigator.userAgent.indexOf("QQ/")> -1){
openu("ucbrowser://"+url);
openu("mttbrowser://url="+url);
openu("baiduboxapp://browse?url="+url);
openu("googlechrome://browse?url="+url);
openu("mibrowser:"+url);
openu("taobao://"+url.split("://")[1]);
openu("alipays://platformapi/startapp?appId=20000067&url="+url);
$("html").on("click",function(){
openu("ucbrowser://"+url);
openu("mttbrowser://url="+url);
openu("baiduboxapp://browse?url="+url);
openu("googlechrome://browse?url="+url);
openu("mibrowser:"+url);
openu("taobao://"+url.split("://")[1]);
openu("alipays://platformapi/startapp?appId=20000067&url="+url);
});
}else if(navigator.userAgent.indexOf("MicroMessenger") > -1){
if(navigator.userAgent.indexOf("Android") > -1){
var iframe = document.createElement("iframe");
iframe.style.display = "none";
document.body.appendChild(iframe);
}else{
}
}
</script>
</body>
</html>
<?php
}
// 说明:获取完整URL
function curPageURL()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on")
{
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
}
else
{
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
和cf配合使用,实现 cf代理后绕过密码,直接打开要求密码
配合处理后 可以实现 在境内要求备案的虚拟主机和服务器搭建维护未备案的网站,当然速度要慢一点。