Page 1 of 1

Help Plz - recursive include - variable not visible

Posted: Sat Mar 29, 2008 4:27 pm
by theepan
Hello There,

I am trying to include one php file that includes another php file. All three files are in different folders. The variables in first php page is not visible.


Folder Structure:

Webapp
-config/config.php
-incs/header.php <- includes config
-public_html/index.php <- includes config.

Variables in config.php from header.php is not visible in index.php.
If I run header.php, config.php variables are visible.


Code:
index.php
------------------------------

Code: Select all

 
<?php
require_once("../../incs/header.php");
 
head('Home');
 
foot();
?>
 
 
header.php
-----------------------------

Code: Select all

 
<?php
include_once("../config/config.php");
 
function head($title = " "){
    ?>
    <html>
    <head>
    <title><? echo "$title - $glo_title"?></title>
    </head>
    <body>
    <?php
   
}
 
 
 
 
function foot(){
    ?>   
    </body></html>
    <?php
}
 
?>
 
config.php
-------------------------------

Code: Select all

 
<?php
/** TITLE */
global $glo_title;
$glo_title = "123auto";
 
 
/** USERNAME/PASSWORDS */
 
//MySQL
global $username;
global $password;
 
$username = "testuser";
$password = "test";
?>
 
 
-----
THx in advance :D

Re: Help Plz - recursive include - variable not visible

Posted: Sat Mar 29, 2008 5:02 pm
by Christopher
index.php

Code: Select all

<?php
require_once("../incs/header.php");
 
head('Home');
 
foot();
?>

Re: Help Plz - recursive include - variable not visible

Posted: Sat Mar 29, 2008 10:19 pm
by theepan
That didn't help... Thanks anyway

Re: Help Plz - recursive include - variable not visible

Posted: Mon Mar 31, 2008 12:29 am
by sarmadmahar
Hello,
it is possible to use variable from different files. just just Global keyword,


EDIT | Chris Corbyn says 'no thanks' to your irrelevant advertisement sarmadmahar!

Re: Help Plz - recursive include - variable not visible

Posted: Mon Mar 31, 2008 1:39 am
by it2051229
am sorry to say but i've been doing an include like

Code: Select all

include("../DatabaseConnector.php");
and it really doesn't work whenever it has something like "../" in the path.. i dont know why.. it's supposed to be working it just ruined my project directory structure

Re: Help Plz - recursive include - variable not visible

Posted: Mon Mar 31, 2008 2:37 am
by deejay
how about using something like

Code: Select all

 
include ("".$_SERVER['DOCUMENT_ROOT']."includes/config.php");
 
 
there's a useful list of $_SERVER commands at http://uk.php.net/reserved.variables