Page 1 of 1
include outside of a function
Posted: Wed Feb 18, 2004 5:03 pm
by defx
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.
Posted: Wed Feb 18, 2004 5:05 pm
by Dr Evil
Could you show me some code?
Posted: Wed Feb 18, 2004 7:58 pm
by defx
what I did is i created a file called cfg.php:
then in a seperate file:
Code: Select all
<? include ("cfg.php");
Function function1()
{
echo "$var1";
}
?>
and it did not work

Posted: Wed Feb 18, 2004 8:05 pm
by mikegotnaild
good question
Posted: Wed Feb 18, 2004 8:14 pm
by markl999
You would have to do :
Code: Select all
<? include_once 'cfg.php';
function function1()
{
global $var1;
echo $var1;
}
?>
Posted: Thu Feb 19, 2004 2:13 am
by Dr Evil
Thanks Mark 'Connery' 999 beat me to it.