热搜词
发表于 2021-10-9 15:08:13 | 显示全部楼层 |阅读模式
这个php脚本在每个目录生成内容为空的 index.html,可以防止网站源码以及网站资源被窥探。尤其像years4这样的黑客 本程序参考了xuxu的一个目录遍历函数 源代码如下:

<?php
//配置
$root_dir = '/www/caitupian'; // 根目录
$default_content = ' ';  //生成的index.html文件默认内容
//开始执行
function rscandir($base = '',$return = 'all', &$data = array()  ) {
        $ds = '/'; // DIRECTORY_SEPARATOR
        $base = rtrim($base,$ds).$ds;
        $array = array_diff(scandir($base), array('.', '..', '.svn'));
        foreach ($array as $value) {
                if (is_dir($base . $value)) {
                        if($return != 'file')
                        $data[] = $base . $value . $ds;
                        $data = rscandir($base . $value . $ds, $return, $data );
                } elseif (is_file($base . $value)) {
                        if($return == 'dir') continue;
                        $data[] = $base . $value;
                }
        }
        return $data;
}
$dirs = rscandir($root_dir, 'dir');
$current_path = str_replace('\\', '/', dirname(__FILE__));
$source_path = $current_path.'/index.html';
file_put_contents($source_path, $default_content);

foreach ($dirs as $d)
{
        copy($source_path, $d.'index.html');
}
本程序可以直接在浏览器里运行或者在命令行下运行。

全部评论0
回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|管理员之家 ( 苏ICP备2023053177号-2 )

GMT+8, 2024-6-29 21:09 , Processed in 0.173037 second(s), 22 queries .

Powered by Discuz! X3.5

Cpoyright © 2001-2024 Discuz! Team