gpt4 book ai didi

php - 文件存在安全吗?

转载 作者:可可西里 更新时间:2023-11-01 00:01:43 25 4
gpt4 key购买 nike

if (file_exists("pages/$page.php")) {
include($page.'.php');
}

这样安全吗?

对于 Safe,我的意思是您不能包含远程脚本等

最佳答案

当然不是,尤其是 $page = "./configuration"

我建议用这样的东西替换它:

$pages = array("blog", "home", "login");
if (in_array(strtolower($page), $pages))
include("pages/$page.php");

编辑:您可以使用此代码生成可接受页面列表。

$pages = array();
if ($dh = opendir("pages")) {
while (($file = readdir($dh)) !== false) {
if (strstr($file, ".php") !== false) // make sure it is a .php file
$pages[] = substr($file, -4); // remove the .php
}
closedir($dh);
}

关于php - 文件存在安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1342190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com