繁体   English   中英

找出包含哪些文件,使用PHP渲染URL

[英]Figuring out which files are included rendering a URL with PHP

我如何使用php确定仅在给定URL的情况下调用和包含哪些文件。

例如。 URL,www.mydomain.com / index.php

可能使用:

  • index.php
  • includes.php
  • content.html

我想给php的网址,并返回文件名。

谢谢 :-)

您将无法通过URL执行此操作。 对于外界来说,URL只是返回一堆文本的东西。 几乎无法做任何事情来说明该文本是如何创建的。

如果您有权访问源代码,请将其放在条目文件的末尾将有很大帮助。

print_r(get_included_files());

这将打印出其中包含或需要的每个文件。但是,这不会为您提供任何使用fopen,file_get_contents等访问过的文件。如果您有兴趣查看是否已访问特定文件, Unix stat程序可以告诉您这一点。 但是,在正常的计算机操作中,由于多种原因而访问文件,因此您需要谨慎地依赖stat产生的任何内容。

您需要get_included_files()函数。

仅提供URL就无法做到这一点,因为PHP支持动态包含文件,并且您的代码可能采用不同的执行路径。 在PHP脚本中,可以在包含所有文件之后使用get_incluided_files()

这是PHP文档中的示例:

<?php
// This file is abc.php

include 'test1.php';
include_once 'test2.php';
require 'test3.php';
require_once 'test4.php';

$included_files = get_included_files();

foreach ($included_files as $filename) {
    echo "$filename\n";
}

?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM