will taubin wrote:[color=blue]
> i would like my program to have a config.php with passwords and other
> stuff.
>
> i would like to have a functions.php to hold all my functions.
>
> i would like the functions.php to include/require the config.php as it
> will need it for database stuff.
>
> i cant seem to get the functions in my functions.php to see the
> variables in config.php
>
>
> when i run the following on my machine i just get notices about the
> undefined variables. what is wrong with this?[/color]
You're using the variables defined in config.php _inside_ the function.
That turns them out of scope.
see
http://www.php.net/manual/en/languag...bles.scope.php
Either declare them global within the function, or (better, I think)
make them constants in config.php
declaring the variables global:
<?php // functions.php
function my_function() {
global $user, $server, $pass;
print("user: $user , server: $server , pass: $pass ");
}
?>
making them constants:
<?php // config.php
declare('USER', 'root');
declare('SERVER', 'localhost');
declare('PASS', 'pass');
?>
<?php // functions.php
function my_function() {
echo 'user: ', USER, ' , server: ', SERVER, ' , pass: ', PASS, ' ';
}
?>
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.