如何获取使用“require_once”的页面的URL


How can i get the URL of the page that used "require_once"

我创建了一个有3个页面的PHP站点,即A,B和C。A 和 B 都将首先使用"require_once"调用页面 C。有没有办法让页面 C 知道这个调用是来自 A 还是来自 B?

$_SERVER['HTTP_REFERER']没有用。

A.php

$page = 'A';
require_once 'C.php';

B.php

$page = 'B';
require_once 'C.php';

C.php

echo 'I was required by'.$page;

你可以在 c 中使用debug_backtrace函数.php
您还将获得呼叫者文件和呼叫者线路号码。

$db =  debug_backtrace();
echo "Calling file: ". $db[0]['file'] . ' line  '. $db[0]['line'];

试试 $_SERVER['REQUEST_URI']。每 php.net,

URI 提供整个请求路径(/directory/file.ext?query=string)