Forum Moderators: coopster

Message Too Old, No Replies

PHP include(); not grabbing variables

what am I doing wrong?

         

wfernley

6:40 pm on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone.

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

willybfriendly

6:57 pm on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Any error messages that you can share?

Also, check the html source that your browser is seeing. might give some clues as to what is going on.

Finally, make suer your file permissions are set correctly.

WBF

wfernley

7:06 pm on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the reply willybfriendly.

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

geotopolis

8:04 pm on Jan 28, 2005 (gmt 0)

10+ Year Member



Its kind of hard trouble shooting when you don't see any code.

Did you use
<pre>
<?php print_r($CFG)?>
<?pre>
to see what if anything is in $CFG?

If nothing is did you instantiate $CFG? It is a class
right your using -> to access the variables.

-Matt

wfernley

8:50 pm on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah I have tried printing the variable and its blank. I am not defining a class though. Should I be?

If you need some code I can post some.

wfernley

8:57 pm on Jan 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The application.php has:

$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

geotopolis

9:40 pm on Jan 28, 2005 (gmt 0)

10+ Year Member



Something funny is going on (as if you don't know).

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.

willybfriendly

5:03 am on Jan 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is wwwroot outside of your web accessible directory? If so, setting it to [mysite.com...] will not work.

Try using $_SERVER['DOCUMENT_ROOT'] instead and see what happens.

WBF