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

I created a PHP site that has 3 pages, i.e., A, B, and C. Both A and B will call page C first by using "require_once". Is there a way for page C to know if this call came from A or B?

$_SERVER['HTTP_REFERER'] didn't work.

A.php

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

B.php

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

C.php

echo 'I was required by'.$page;

You can use debug_backtrace function in c.php
You will get caller file and caller line nos as well.

$db =  debug_backtrace();

echo "Calling file: ". $db[0]['file'] . ' line  '. $db[0]['line'];

Try $_SERVER['REQUEST_URI']. Per php.net,

URI provides the entire request path (/directory/file.ext?query=string)