include outside of a function
Moderator: General Moderators
include outside of a function
Is it possible to include a file, then later inside of a function, use a variable listed inside the included file? I tried it and it said that my variable was not definied. so i ended up having to include the file in the function.
what I did is i created a file called cfg.php:
then in a seperate file:
and it did not work 
Code: Select all
<? $var1 = "variable 1"; ?>Code: Select all
<? include ("cfg.php");
Function function1()
{
echo "$var1";
}
?>You would have to do :
Code: Select all
<? include_once 'cfg.php';
function function1()
{
global $var1;
echo $var1;
}
?>