Relationship of variables between php files

Hi everyone,

I’m curious as to how variables move in php. If a variable is created in a template then $_POST’ed back to the controller which then put’s that variable in a file called $variable which is then sent to another template to display some info then sent back again to the controller for deletion.

Must I always re’$_POST my variables between .php files?

Thanks

Hi ellypho, welcome to the forums,

Always? Not at all.

But it’s perhaps the most common and easiest way to pass variables, depending.

$_GET if trivial and there aren’t many
Cookies if trivial and there aren’t many
$_SESSION is another common way but a little trickier until you get used using to them
INSERT into a database table, more over-head and probably only if you want to save across sessions
File Write (eg. XML CSV), more over-head and probably only if you want to save across sessions

IMHO except for $_GET the other ways will be more verbose code.

Or maybe you could write things so there is no need to pass, but include instead?