PHP输入密码并列出目录文件生成超链接代码

一个可以加密文件夹,并且可以展示文件夹内文件的php代码:

<?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"])) ? "需要密码才能查看,请输入密码。" : "密码不正确,请重新输入。"; 
} 
}else{ 
$isview = false; 
$p = "请输入密码查看,获取密码可联系我。"; 
} 
} 
if($isview){ ?> 
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>加密内容</title>
<meta name="Keywords" content="加密内容" />
<meta name="Description" content="加密内容" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div id="post">
<pre id="neirong">
<?php   
$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 "<a href=./".$file.">".$file."</a><br>";   
       }   
       }   
       closedir($dh);   
   }   
}   
?>
</pre>
</div>
</body></html>
<?php }else{ ?> 

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>输入密码</title>
<meta name="Keywords" content="输入密码" />
<meta name="Description" content="输入密码" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div id="post">
<img src="key.png" alt="PHP输入密码并列出目录文件生成超链接代码">
<form action="?yes" method="post" style="margin:0px;">输入查看密码 
<input type="password" name="pwd" /> <input type="submit" value="查看" /> 
</form> 
<?php echo $p; ?> 
</div> 
<?php 
} ?> 
</body> 
</html>

进阶版本 修改了背景图片,增加退出(返回指定地址)、返回上一目录按钮。

<?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()+10*3); //设置密码过期时间 10秒。切换目录需要重新输入密码
$isview = true; 
}else{ 
$p = (empty($_POST["pwd"])) ? "需要密码才能查看,请输入密码。" : "密码不正确,请重新输入。"; 
} 
}else{ 
$isview = false; 
$p = "内部文件请输入密码查看。"; 
} 
} 
if($isview){ ?> 
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>加密内容</title>
<meta name="Keywords" content="加密内容" />
<meta name="Description" content="加密内容" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<a href="JavaScript:history.back(-1)">点击返回</a>
<a href="http://0912itw.com">退出</a>
<div id="Layer1" style="position:fixed;z-index:-100; left:0px; top:0px; width:100%; height:100%">
        <img src="http://xxxx.com/1.jpg" alt="PHP输入密码并列出目录文件生成超链接代码" width="100%" height="100%"/>
    </div>  <!-- 设置网页背景图片 -->
<body>
<div id="post">
<pre id="neirong">
<?php   
$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 "<a style='font-size: 25px;text-decoration:none;
' href=./".$file.">".$file."</a><br>"; //a style='font-size: 25px;text-decoration:none; '为修改输出变量的字体大小代码 
       }   
       }   
       closedir($dh);   
   }   
}   
?>
</pre>
</div>
</body></html>
<?php }else{ ?> 

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>输入密码</title>
<meta name="Keywords" content="输入密码" />
<meta name="Description" content="输入密码" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<div id="Layer1" style="position:fixed;z-index:-100; left:0px; top:0px; width:100%; height:100%">
        <img src="http://xxxx.com/1.jpg" alt="PHP输入密码并列出目录文件生成超链接代码" width="100%" height="100%"/> 
    </div> <!-- 设置网页背景图片 -->
<body>
<div id="post">
<img src="key.png" alt="PHP输入密码并列出目录文件生成超链接代码">
<form action="?yes" method="post" style="margin:0px;">输入查看密码 
<input type="password" name="pwd" /> <input type="submit" value="查看" /> 
</form> 
<?php echo $p; ?> 
</div> 
<?php 
} ?> 
<?php 

 ?> 
</body> 
</html>

 

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: