一个可以加密文件夹,并且可以展示文件夹内文件的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="gb2312" /> <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="gb2312" /> <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"> <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>
来源:https://diannaobos.com/post/567.html
评论 (0)