This should work, so I\'m really perplexed about why it\'s not working.
I\'m checking to see if a user is logged in using a $session class method at the top of each
Instead of if (!logged)
, try if (empty($logged))
. That won't generate a notice in cases where the variable hasn't been set.
Variables do propagate to the included files, so it must be, that the variable is NOT set when you call the include: try checking if so, then figure out why is the variable not set at that point.
For example, if you defined $logged inside the "if" block or inside a function, then it won't propagate outside of it: you must define it in the outermost scope (at the same level at which you call the include statement). And you must define it for the case that the user is not logged in, not only for the case when the user is logged in. If the variable is not initialized to false, the check if(!$logged) will issue warning. Say $logged = false; at the beginning of your work.
Just an opinion... instead of including code to execute in the global space and depending on another global variable being defined, include your file wherever and have the code inside header.php be organized into appropriate functions. Then where you want the output from header.php, call the appropriate function with the $logged as an argument. This will help make your code more cohesive and easier to test (as in unit tests).
Try something very simple, like
// file1.php
$var = "foobar";
// file2.php
include("file1.php"); // or require("file1.php");
die($var);
Does it work? Maybe it's a problem outside your code.