My PHP is set up in a way where each page runs as followed:
require('config.php'); //variables, db, etc
$content = "all page output";
require('design.php');
However - any time a page called with require()
from design.php
it cannot read any variables. $vars
, get
, post
, globals, constants, etc. All I can seem to get it to run are session variables. It should be noted that the variables load fine if I cut/paste the code from the require()
files straight to design.php
.
From my understanding include()
/require()
acted as if the code was just cut and pasted in the desired spot. However, this is giving me a world of issues.
*Code breakdown*
config.php
$systemProductURL = 'http://test.com/cart/';
$systemProductURL is the variable which isn't being passed along the entire way. I can echo it out fine from config.php.
design.php
include $systemProductURL . 'inc/components/defaultMainMenu/display.php';
This page is entirely design, it does no calculations or change variables in anyway. It uses $systemProductURL to call display.php. $systemProductURL works fine here in design.php but is unreadable in display.php. I know the include() is reaching the desired file as I can echo out plain text from display.php just fine.
display.php
<? echo $systemProductURL; ?>
This is where the problem is. For the life of me I cannot get display.php to echo $systemProductURL. This is the entire page.
The page that the user visits. I'll use my homepage, index.php as example
require 'inc/config.php';
$pageContent .= "
<div class='pageContentBody' style='width: 100%'>
content
</div>";
require 'inc/design.php';
This page and any other page that is visited by the user can use $systemProductURL perfectly.