TheGuyWhoCodes TheGuyWhoCodes - 8 months ago 22
JSON Question

Store a PHP variable once throughout a webpage.

So I have a a variable called json that stores all of the json. I want to load this once in the site, and be able to use it through any php function that I have. So let's say I have this line of code placed at the beginning of index.php:

$json = file_get_contents('http:/xxxxxxxx/bp.json');

I want to be able to use this variable from a function somewhere else in the page, WITHOUT loading it again.



You could store your variables in the PHP session and call it anywhere in your application.

$_SESSION["favcolor"] = "green";

Also best practices is to destroy and/or clear all your session variables upon exiting your application.