Hello,

I am making an online gallery for a friend and have this (partially listed) folder structure.

root/index.php
root/inc/gallery.inc.php
root/inc/setup.inc.php
root/inc/includes.inc.php

Gallery.inc.php has various functions in it (Get image, album, etc), setup.inc.php has config variables (for my friend's ease of access, contains SQL stuff and date formats), here is what includes.inc.php looks like:

<?php
require "setup.inc.php";
require "gallery.inc.php";
?>

index.php has this code at the top:

<?php
include "inc/includes.inc.php";
?>

What I would like to do is use variables and functions FROM settings.inc.php IN gallery.inc.php.

I can access functions from settings.inc.php in gallery.inc.php but not variables...

No there is no "class ______" calls anywhere and therefore I see no problem with my code.

Any and all help is appreciated,

-- Turt2Live

Where is settings.inc.php in included?
In index.php OR includes.inc.php?
And what is the order of include coding?

Sorry, I didn't realize that,

settings.inc.php and setup.inc.php are the same file.

Member Avatar for diafol

> settings.inc.php and setup.inc.php are the same file.

O man, now I am confused. :(

In my original post I said in the includes.inc.php file there was this line:

require "setup.inc.php";

But I went on to explain a "settings.inc.php".

Both of these files are the same file.

Can you post how your variable is defined in setup.inc.php and how did you used it in gallery.inc.php?

Setup.inc.php:

<?php
/* START USER CONFIG */
$SQL_HOST =			"localhost";
$SQL_USER = 		"*****";
$SQL_PASS = 		"*****";
$SQL_DATABASE =		"*****";

$DATE_FORMAT =		"d/M/Y H:i:s A";
$TIMEZONE = 		"America/Edmonton";

$LOCATION = 		"http://turt2live.com/newgallery";

/* END USER CONFIG */
?>

gallery.inc.php:
(This is partial code, the file is a wee bit long, but it is where I am getting issues.)

$q = mysql_query("SELECT * FROM `images` ORDER BY RAND() LIMIT ".$show);
if(mysql_num_rows($q) > 0){
	$ret = $ret . "<div>";
	while($a = mysql_fetch_array($q)){
		$img_src = 				$a['image_location'];
		$img_name = 			$a['image_title'];
		$img_thumb_src = 		create_thumbnail($img_src, "cache/image_temp_".$img_name.".png", true);
		$album_link = 			$LOCATION . "/album.php?name=".$a['album_name']."&username=".$a['username'];
		$album_name = 			$a['album_name'];
		$username = 			$a['username'];
		$ret = $ret . "<div class='imagecontainer'>";
		$ret = $ret . "<a href='".$img_src."' rel='lightbox-ALBUMNAME' title='".$img_name." (".$album_name.", by ".$username.")'><img src='".$img_thumb_src."'></a><br>";
		$ret = $ret . "<b>".$img_name."</b><br>";
		$ret = $ret . "(<a href='".$album_link."'>".$album_name."</a>)<br>";
		$ret = $ret . "By: <a href='".$LOCATION."/user/".$username."'>".$username."</a>";
		$ret = $ret . "</div>";
	}
	$ret = $ret . "</div>
}";

I am trying to use the $LOCATION variable.

Is the code you have posted here for gallery.inc.php is in any function? Or it is outside? If its inside you need to make it global.
Generally i am always defining configuration variables.
e.g. define('SQL_HOST','localhost'); so that i can use it any where inside function.

Yes it's in a function,

so would I change the $LOCATION to define('LOCATION', 'http://www.rest/of/address'); and call it in gallery.inc.php as $LOCATION or somehow else?

1) either you need to make all config variable global inside function.
i.e.

function fname()
{
    global $LOCATION;
// now you can use $LOCATION
}

2) or you can define in Setup.inc.php:

define('LOCATION', 'http://www.rest/of/address');
// now you can use LOCATION (without  $ sign) in function file.
commented: Amazing help +3

Alright, thanks for your help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.