I know this works.
$variable = "value";
global $variable; echo $variable;
Is it possible to set a global variable in template page or include php file?
Anywhere in your script, you can define a global variable as follow:
Using the superglobal
It's an associate array, containing all global variables as a key-value pair. ie: the key will be the variable name, and value will be the value of the variable.
And it can be accessed as:
to know more ref: PHP Variable Scope
EDIT: While answering i assumed the user knew about method 2, but on rereading it seems maybe he is not aware of it, so am mentioning it below.
you can define global variable using the 'global' keyword as well. eg code:
Note: The code is untested