View Full Version : Vars not being passed...

03-05-2008, 11:55 PM
Okay, slideshow.php defines 2 variables, $array1 and $var2.

slideshow.php is then included in header.php in the normal include manner.

header.php contains 1 check against the existence of $array1.

footer.php also contains 1 check against $array1 and if it exists, prints $var2.

Even though $array1 exists and is printed by slideshow.php within itself, it fails the check by $header.php and $footer.php.

If I just paste the code from slideshow.php into header.php rather than include it, then $array1 passes the check on header.php, but still not on footer.php.

What’s up with that? :-D

Here's a further description of how the files associate...
- slideshow.php is included in header.php
- header.php and footer.php are included in just about every other public file on the site. header.php contains all the code before the main content info of a page and footer.php everything after. You get the idea.

I should add that the slideshow.php file is definitely being included. The jscript is printed with the php code being parsed correctly within the slideshow.php file. Where the jscript array for the images is built by the php. That's working fine and being shown correctly if I view the source of the final page in a browser.

Below is the code for slideshow.php and subsequently the places in header.php and footer.php where variables from slideshow.php are called:

//Get image names from folder
$imageFileLoc = opendir($siteBasePath.'images/slideshow-images/');

while (false !== ($imageFile = readdir($imageFileLoc))) {
if (($imageFile != '.DS_Store') && ($imageFile != '_notes')){
$imageFiles[] = trim($imageFile);


//Setup slideshow placeholder
$slideShow = '<table border="0" cellpadding="0" cellspacing="0">' .
'<tr>' .
'<td id="VU" height=160 width=124>' .
'<img src="'.$imageFiles[1].'" name="SlideShow" width=160 height=124></td>' .
'</tr>' .

// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this header
// NS4-6,IE4-6
// Fade effect only in IE; degrades gracefully

// =======================================
// set the following variables
// =======================================

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000

// Duration of crossfade (seconds)
var crossFadeDuration = 3

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

//Get filenames from slideshow folder
for ($i=2; $i < count($imageFiles); $i++){
$picIndex = $i - 2;
print "Pic[".$picIndex."] = '/images/slideshow-images/".$imageFiles[$i]."';";

// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad[i] = new Image()
preLoad[i].src = Pic[i]

function runSlideShow(){
if (document.all){
document.images.SlideShow.src = preLoad[j].src
if (document.all){
j = j + 1
if (j > (p-1)) j=0
t = setTimeout('runSlideShow()', slideShowSpeed)

between the head tags to include the jscript:
<?php fileInclude('/php-bin/slideshow.php'); ?>

AND in the body to load the slideshow jscript if there is an array:
<?php print ((is_array($imageFiles))? '; runSlideShow()' : ''); ?>

Where the slideshow is placed:
<?php print ((is_array($imageFiles))? $slideShow : '<img src="/images/page_photo.png" />'); ?>


03-06-2008, 03:31 AM
Did you make your own function for including files? Can we see that function?

03-06-2008, 12:57 PM
Yeah, sorry 'bout that! Forgot I had done that! :)

//Includes the file specified as $location
function fileInclude($file){
global $siteBasePath;

It just inserts the server's base path for me.

Think it may be the problem?

03-06-2008, 04:53 PM
It shouldn't be. Have you checked to see if the array is getting the values you want? Do a print_r($imageFiles); to see if the array was even populated.

Also what is $siteBasePath? Is it simply $_SERVER['DOCUMENT_ROOT']? If it is have you checked to see what that returns? If it returns what I think it does then this line

$imageFileLoc = opendir($siteBasePath.'images/slideshow-images/');
tries to open this directory
[php]$imageFileLoc = opendir('home/user/public_htmlimages/slideshow-images/');
Usually the trailing forward slash isn't returned.

03-06-2008, 05:37 PM
Yeah, the $imageFiles array is spit out into a javascript array. That all happens within the slideshow.php file. That's definitely working.

I switched all my includes to:


The $siteBasePath is defined as

$siteBasePath = '/var/www/vhosts/calvarychapelac.com/httpdocs/';
inside another include file (include.php) that is included on every page at the top with the full path.


Now everything is working fine that I got rid of the function.

Someone else told me I couldn't use the include function inside another function. So, I just dropped it and stuck the base path in at each include statement (what I was trying to avoid).

03-06-2008, 06:17 PM
You could easily do something like


03-06-2008, 06:29 PM
Awesome! Thanks!

I'm still just a young padawan to the php. :)