GeorgeMoney Posted September 10, 2006 Share Posted September 10, 2006 Would there be a way to have something be "not-included" when you include a file? The only way I can think of is having an if statement and if the $_SERVER['SCRIPT_....'] var doesn't match the ___FILE___ constant then don't execute the stuff you don't want included. Is this the only way? Quote Link to comment Share on other sites More sharing options...
btherl Posted September 10, 2006 Share Posted September 10, 2006 Can you give a bit more detail about your situation?You can certainly say[code]if (some test) { require_once('file.php');}[/code]But it sounds like you want something not so straightforward? Are you trying to detect the name of the script which is including a particular file, from within that included file? Quote Link to comment Share on other sites More sharing options...
GeorgeMoney Posted September 10, 2006 Author Share Posted September 10, 2006 Basically I have one index.php file. On the index.php file there is something like:[code]<?phprequire_once "includes.php";starts();editbutton();if(isset($_GET['images'])) {require_once "images.php";} elseif(isset($_GET['contact'])) {require_once "contactus.php";} else {require_once "main.php";}?>[/code]The editbutton() checks if the user is logged in and adds an editbutton on top linking to a file editor if they are logged in. I also want to have the editbutton on main.php itself, so if the user wants to edit that they can easily.But if I do that, then I have the editbutton from main.php and the editbutton from index.php both on index.php. I want it to only use index.php's edit button on index.php and main.php's edit button on main.php. Is this possible? Quote Link to comment Share on other sites More sharing options...
btherl Posted September 10, 2006 Share Posted September 10, 2006 You could set a variable. Variables set in index.php can be seen by main.php. For example[code]... } else { $editbutton_displayed = true; require_once "main.php";}And in main.php:if ($editbutton_displayed != true) { editbutton();}[/code]Another name for the variable could be "$in_index_php", which might be more appropriate. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.