1 不可行方案,只能全局加密,不能目錄
- 只是在index.php做判斷枣察,然后顯示輸入密碼 (目錄在 _h5ai/public/index.php)
<?php
$lifeTime = 60; //設置密碼過期時間
session_set_cookie_params($lifeTime);
session_start();
if(isset($_POST['password']) && $_POST['password'] == 'siji'){
$_SESSION['ok'] = 1;
header('location:?');
}
if(!isset($_SESSION['ok'])){
exit('
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/_h5ai/public/css/styles.css">
</head>
<body class="info" id="root">
<div style="height:100px; line-height:100px;" align="center" valign="center">
</div>
<div id="login-wrapper" style="height:100px; line-height:40px;" align="center" valign="center">
<img src="https://oclog.pw/doc/zq.jpg"/ width="280px" height="280px">
<h2 id="header"class="h1" >
輸入密碼
</h2>
<form method="post" class="form" >
<input id="pass" name="password"/>
<input type="submit" id="login" value ="確認" style="border:none;background:#42a5f5"/>
</form>
</div>
</body>
</html>
');
}
?>
QQ截圖20171230011021.png
2争占、可行方案,通過nginx認證
參考網(wǎng)址 nginx 官方加密教程
在網(wǎng)站對應的conf中配置如下 (/www/server/panel/vhost/nginx)
#禁止訪問的文件或目錄
location ~ ^/(\.user.ini|\.htaccess|\.git|\.project|LICENSE|README.md)
{
return 404;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$
{
expires 12h;
access_log off;
}
---------------------------------------------------------------------------------
location ~ /secret_h {
auth_basic "root";
auth_basic_user_file /www/wwwroot/htpasswd;
}
------------------------------------------------------------------------------
- 增加的部分是虛線部分询件, ~ 表示匹配開頭燃乍,遞歸全部目錄 (不懂得參考!nginx 中l(wèi)ocation的用法)
- htpasswd 采用 crypt加密宛琅,參考 crypt在線
QQ截圖20171230012859.png