Forum Moderators: coopster
I have been using a script where I have a main file called application.php where it stores all my main variables and connections to the DB. Now in that file I have a variable called $CFG->wwwroot which is equal too [mysite.com....] I also have another variable that holds my includes which is $CFG->incdir. It is equal too $CFG->wwwroot/includes.
All my php files call this file. Now I have other files that I include for like my header and footer. For some reason though whenever I call these files they show up but the images in those files don't work. It's like the $CFG->wwwroot variable isn't being passed to those included files.
Does anyone know why this is? What am I doing wrong? :)
Thanks for your help!
Wes
It doesn't give off an error. It just displays blank. Like I have a variable for images which is $CFG->imgdir. It has the value of [mysite.com...] So all my images in that include file have <img src="<?=$CFG->imgdir?>/logo.gif"> but all that comes up in the source is /logo.gif. It is like the variable is not being passed.
What about the file permissions. Do you mean CHMOD? if so, what should they be set too?
Thanks again
Wes
$CFG->wwwroot = "http://www.mysite.com";
$CFG->incdir = "$CFG->wwwroot/inc-files";
$CFG->imagedir = "$CFG->wwwroot/images";
The index.php page has this(just part of the idnex.php code is here - whats relevant anyways)
<?php
include("application.php");
?>
<html>
<html>
<HEAD>
<title>mysite</title>
</HEAD>
<body>
<?php include("inc-files/header.php");?>
*************index.php body******************
<?php include("inc-files/footer.php");?>
now header.php has:
<img src="<?=$CFG->imagedir?>/logo.gif">
Now when index.php loads up and I view source for the logo image I only see /logo.gif and not the full path. It is like the variable is not being passed to the included file.
Is it because I havent defined $CFG as a class or object?
Thanks for your help.
Wes
If that all you have then it should work. And you can
make some test files as an example.
You are treating CFG like an object if you didn't explicitly declare it then an object of type stdClass
is used.
Here is a couple ideas to narrow down the problem.
In application.php use print_r($CFG) to see if that section is ever being run. Also at the end of application you might print_r($CFG) to see if its being deystroyed or reset. Right after you include it index.php print_r($CFG) and see if its holding a value. My guess is its not, if it was it should exist for your header file.
I also try and use require_once and include_once instead of just require and include.
You can also use <?= __FILE__?> right before the print_r which will show you what file the output is coming from.
Try using $_SERVER['DOCUMENT_ROOT'] instead and see what happens.
WBF