加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 文件存在安全吗?

发布时间:2020-12-13 21:59:54 所属栏目:PHP教程 来源:网络整理
导读:if (file_exists("pages/$page.php")) { include($page.'.php');} 这样安全吗? 使用Safe我的意思是你不能包括远程脚本等 解决方法 当然不是,特别是如果$page =“./ configuration” 我建议用这样的东西替换它: $pages = array("blog","home","login");if (
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);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读