Jump to content

Archived

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

GeorgeMoney

no-include

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Basically I have one index.php file. On the index.php file there is something like:
[code]<?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";
}
?>[/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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.