echo文件名';包括';不是';包括';


echo name of file 'including' not 'included'

好的,所以我在每个页面上制作一个网站,我想在那里include一个文件sidebar.hp.

在sidebar.php中,我想回显包含sidebar.php.的文件名

以下是sidebar.php的内容,它们返回"sidebar"。

<?php 
$file = basename(__FILE__, '.php');
echo $file;
;?>

我发现了一个类似的问题,但关键是我不必在每一页上都不加任何变量。

请原谅我含糊其辞地使用了include这个词,我在php中使用it作为语句。

您可以通过会话变量将其传递到侧边栏页面

<?php
    session_start();
    $_SESSION['filename'] = "thisFilesName.php";
    include('../sidebar.php');
?>

sidebar.hp:

<?php
    session_start();
    echo $_SESSION['filename'];
?>
相关文章: