php列目录设置密码,PHP输入密码并列出目录文件生成超链接代码
一個(gè)可以加密文件夾,并且可以展示文件夾內(nèi)文件的php代碼:
$password = "123456"; // 這里是密碼
$p = "";
if(isset($_COOKIE["isview"]) and $_COOKIE["isview"] == $password){
$isview = true;
}else{
if(isset($_POST["pwd"])){
if($_POST["pwd"] == $password){
setcookie("isview",$_POST["pwd"],time()+3600*3);
$isview = true;
}else{
$p = (empty($_POST["pwd"])) ? "需要密碼才能查看,請(qǐng)輸入密碼。" : "密碼不正確,請(qǐng)重新輸入。";
}
}else{
$isview = false;
$p = "請(qǐng)輸入密碼查看,獲取密碼可聯(lián)系我。";
}
}
if($isview){ ?>
加密內(nèi)容$dir = "./";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file!="." && $file!="..") {
echo "".$file."
";
}
}
closedir($dh);
}
}
?>
輸入密碼輸入查看密碼} ?>
進(jìn)階版本 修改了背景圖片,增加退出(返回指定地址)、返回上一目錄按鈕。
$password = "123456"; // 這里是密碼
$p = "";
if(isset($_COOKIE["isview"]) and $_COOKIE["isview"] == $password){
$isview = true;
}else{
if(isset($_POST["pwd"])){
if($_POST["pwd"] == $password){
setcookie("isview",$_POST["pwd"],time()+10*3); //設(shè)置密碼過期時(shí)間 10秒。切換目錄需要重新輸入密碼
$isview = true;
}else{
$p = (empty($_POST["pwd"])) ? "需要密碼才能查看,請(qǐng)輸入密碼。" : "密碼不正確,請(qǐng)重新輸入。";
}
}else{
$isview = false;
$p = "內(nèi)部文件請(qǐng)輸入密碼查看。";
}
}
if($isview){ ?>
加密內(nèi)容點(diǎn)擊返回
退出
$dir = "./";
$Color = "red";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file!="." && $file!="..") {
echo "".$file."
"; //a style='font-size: 25px;text-decoration:none; '為修改輸出變量的字體大小代碼
}
}
closedir($dh);
}
}
?>
輸入密碼輸入查看密碼
} ?>
?>
總結(jié)
以上是生活随笔為你收集整理的php列目录设置密码,PHP输入密码并列出目录文件生成超链接代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微服务业务日志收集方案,写得非常好!
- 下一篇: 申请汇丰京东铂金卡地址填单位还是住宅好?