Jump to content


Photo

no-include


  • Please log in to reply
3 replies to this topic

#1 GeorgeMoney

GeorgeMoney
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 10 September 2006 - 04:45 AM

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?
--GeorgeMoney

#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 10 September 2006 - 04:53 AM

Can you give a bit more detail about your situation?

You can certainly say

if (some test) {
  require_once('file.php');
}

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?

#3 GeorgeMoney

GeorgeMoney
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 10 September 2006 - 05:36 AM

Basically I have one index.php file. On the index.php file there is something like:
<?php
require_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";
}
?>

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?
--GeorgeMoney

#4 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 10 September 2006 - 06:10 AM

You could set a variable.  Variables set in index.php can be seen by main.php.  For example

... } else {
  $editbutton_displayed = true;
  require_once "main.php";
}

And in main.php:

if ($editbutton_displayed != true) {
  editbutton();
}

Another name for the variable could be "$in_index_php", which might be more appropriate.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users