当前位置:网站首页 / 建站 / 正文

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

时间:2017年12月12日 | 作者 : liuhui | 分类 : 建站 | 浏览: 6606次 | 评论 0

阿里云限量代金券 | 此广告位出租25元/月

一个可以加密文件夹,并且可以展示文件夹内文件的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>


推荐您阅读更多有关于“”的文章

猜你喜欢

网站分类
关注电脑博士
友情链接

分享:

支付宝

微信