我如何才允许require_once的东西取决于哪个页面'需要'呢?

I just had an idea to make things a little cleaner and less cluttered. And I'm wondering if it's at all possible to determine which page is requesting access to another PHP file?

Index.php:

<?php
    require_once('RequiredThing.php');
    // ...
?>

RequiredThing.php:

<?php
    if(INDEX-PAGE REQUESTED THIS)
    {
        // Do stuff.
    }
    else if(ABOUT-PAGE REQUESTED THIS)
    {
        // Do diffrent stuff.
    }
?>

I hope this is making sense.

Try this

<?php
if(basename(__FILE__, '.php') === "index")
{
    // Do stuff.
}
else if(basename(__FILE__, '.php') === "about")
{
    // Do diffrent stuff.
}

?>

Just a little trick to do this . i hope this will help . before require just define $page var.

about.php

  <?php
    $page = 'about';
    require 'RequiredThing.php';
    ?>

Index.php

   <?php
     $page = 'index';
    require 'RequiredThing.php';

RequiredThing.php

if($page == 'about'){
    // Do stuff. 
}elseif($page == 'index'){
    // Do diffrent stuff
}

?>