Jump to content

[SOLVED] How to identify "Who required me"?


duskshine

Recommended Posts

Say I have

a.php: 
------------
<?php
require_once "c.php";
?>

& b.php: 
------------
<?php
require_once "c.php";
?>

 

How may I code c.php so that it knows it's required by a.php and not b.php, without changing a.php & b.php?

(that is, what should I use to replace the IF_REQUIRED_BY below?)

c.php: 
------------
<?php
IF_REQUIRED_BY("a.php")
    echo "gotcha!"
?>

 

 

 

Thanks,

Link to comment
Share on other sites

Since require literally views the contents of the required file as part of the requiring file, I don't know that this is possible. The only way I know of to do this is to set a variable in the requiring file that is then checked within the required file. Basically, just set up your own check.

Link to comment
Share on other sites

Grab the url of the current page and do a check...since c.php is included in a.php, the url will contain a.php and then you can have c.php echo that information, or whatever else you need.

Link to comment
Share on other sites

Grab the url of the current page and do a check...since c.php is included in a.php, the url will contain a.php and then you can have c.php echo that information, or whatever else you need.

 

What about multi-level file includes? a.php includes b.php and b.php includes c.php... If c.php then does a URL check, it returns the faulty data that it was included by a.php instead of b.php. ;)

Link to comment
Share on other sites

Grab the url of the current page and do a check...since c.php is included in a.php, the url will contain a.php and then you can have c.php echo that information, or whatever else you need.

 

What about multi-level file includes? a.php includes b.php and b.php includes c.php... If c.php then does a URL check, it returns the faulty data that it was included by a.php instead of b.php. ;)

 

Hmmm, didn't think of that. Ignore my previous reply. :)

Link to comment
Share on other sites

 

What about multi-level file includes? a.php includes b.php and b.php includes c.php... If c.php then does a URL check, it returns the faulty data that it was included by a.php instead of b.php. ;)

 

In that case then yes, you would need to have a variable scope, or instead you'd have to create a function for including c.php, where you can report the file name of the current file calling the function.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.