There is no way of achieiving this with include.
You must think about include as of CTRL + C
and CTRL + V
. So as far as Your original code has access to global variable, Your include file also has. It works like pasting new page into a used notebook. It is just an aesthetic operation. Solution? OOP...
You should try to not use global variables, and switch to object oriented programming. If there are no global variables, and everything is stored in the object, the object decide if someone has access to this variable. A short example:
<?php
// "Closed environment"
class NoAccess () {
private $notaccessible;
public __construct ($notaccessibleparam) {
$this->notaccessible = $notaccessibleparam;
}
public method yourfunction() {
print_r($this->notaccessible); // have access
}
}
$instance = new NoAccess(10);
// Further Code dont even know there is a variable called $notaccessible.
// ...
// ...
// But, You can always call:
$instance->yourfunction(); // which have access, and know it.
?>
In that case eveyrhing that You include (in the three dots comments), or write there, cannot use the $notaccessible variable. The only way to use it is using You own interface, such as yourfunction().
This maybe something really new to you, but you should try to read about oop (object oriented programming) in php, while I see your code is quite complicated, and you should switch to oop as fast as you can.
LINKS:
http://php.net/manual/en/language.oop5.php - oop on php.net
http://php.net/manual/en/language.oop5.visibility.php - visibility of variables inside class on php.net
PS. Try to use small letters in <?php
. This is a good habit.