Reputation: 358
I want to store a global variable that exist as long as the application is running and accessible from all the sessions. I tried $GLOBALS but it's not durable. It's temporary, I store the data and when I request the same code again, it says that this index not recognised.
Will I have to store my value in a file?
Edit :: this is a sample code that always print 'not set'
if(isset($GLOBALS['myindex']){
echo 'set';
echo $GLOBALS['myindex'];
}else{
echo 'not set';
$GLOBALS['myindex']='myValue';
}
Upvotes: 0
Views: 1126
Reputation: 1085
Best would be to go with Sessions:
Make sure you add session_start(); at the beginning of the application and it stays throughout the pages. Now you can assign the value to it. via :
$_SESSION['yourkey'] = 'yourvalue'; // you can access it throughout the application
Upvotes: 0