Hi there,
I've just started trying to write my login script with Sessions (a different issue!), however I've put the function to check for login in a seperate php file called functions.php
In this file I write to a variable like this:
$loggedIn = true;
The php file is used in, for example, index.php using
require 'functions.php';
I can call the methods of the functions.php file, however index.php does not seem to see the $loggedIn variable.
Are variables not passed in with the require construct? How would I recode such that I can set the variable in the functions.php file and then just access is from the other php files?
Thanks in advance
Regards
Stu
passing Variables with require
Moderator: General Moderators
Are you accessing or setting this variable within a function? If so then the problem is with your variable scope, read up on it at http://www.php.net.
I thought it could be the variable scope, so I changed the code such that it ends up like:Begby wrote:Are you accessing or setting this variable within a function? If so then the problem is with your variable scope, read up on it at http://www.php.net.
$loggedIn = false;
function foo(){
//stuff
$loggedIn = true;
}
This should mean that the variable does not fall out of scope should it not?
Will check php.net though, cheers!
Regards
Stu