Jump to content

If(included'blah.php') { } else {}


dbs2008uk

Recommended Posts

Hi,

 

I just came accross a situation where I wanted to use the same file twice, once by calling it by name i.e. http://some.com/update.php and the second instance as an include. include'update.php';

 

I wanted update.php to behave diferently depending on whether or not is is included?

 

I ended up doing this:

 

// in dosearch.php

 

$search=1;

include'update.php';

 

// in update php, I check for $search and if its not there and so on......

 

if(!$search) {

$autolayout = 1;

require_once'../../codebase/update.inc.php';

}

 

This works great though Im still curious!!

 

Im wondering a couple of things,:

 

Is there a simple way to see if a .php file is included? i.e. if(included()) { }   

 

or now while writing this Im thinking I should have just made one file with the array in then included this when I need it?

 

So really can I query included() or what would be best practice for this situation?

 

Thanks for your advice in advance.

 

Regards

 

Richard

 

Link to comment
https://forums.phpfreaks.com/topic/103252-ifincludedblahphp-else/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.