Re: Umm.. accessing variables in a required file from another file
| From: | Mark Maggelet | Date: | Thu, 31 Aug 2000 18:58:51 +0000 |
| Subject: | Re: Umm.. accessing variables in a required file from another file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14661@lists.php.net to get a copy of this message | ||
On Thu, 31 Aug 2000 14:40:19 -0400, Chad Day
(cday@beachassociates.com) wrote:
>That's a really bad topic, but I'm not sure how to explain what I
>want so
>shortly.
>
>I have a file that stores global variables (globals.php), such as:
>
>$MESSAGE = "Your login name is $USERNAME, and your password is
>$PASSWORD.";
>
>$USERNAME and $PASSWORD are generated in another file, called
>sendpw.php.
>If I try to use the $MESSAGE variable in sendpw.php, it works, but
>$USERNAME
>and $PASSWORD are not set. How do I go about accessing those
>variables from
>the global file?
they'll still be set unless you're accessing them from inside a
function, in which case you have to use: $GLOBALS["USERNAME"],
$GLOBALS["PASSWORD"]
or else declare the globals at the top of the function:
function foo(){
global $USERNAME, $PASSWORD // has to be at the top
// code goes here ...
}
- Mark