Is it possible to set a Global Variable Available to Every Page?

Permalink
Hello C5 Community:

I would like to create a simple ecourse for kids on our site. Each page will have some informational text or a picture on it, and a question. Kids will have to answer the question (either 'fill in the blank' or multiple choice) based on what they just read or saw.

What I need help with is to have a person's answers from all the pages emailed to me in one email (per person) so I can send them a certificate if answered correctly.

I'm not a current programmer (but understand a few basic php statements). With that in mind I'm looking for a simple solution, hopefully not having to write any database code which is over my head. Is it possible to set a global variable in C5 that is available on every page? If so I would envision just using a php block on each page to ask for an answer, and adding the results to the global variable. After the last question the string would be emailed to me and reset for the next visitor. Not pretty but really all I need...

If the above is not possible, could anyone who has used the addon 'Block Designer' tell me if it is capable of doing what I am looking for.

Any other suggestions on alternative ways of doing this are much appreciated!

Thank you,
Stephan

 
jero replied on at Permalink Reply
jero
I think what you're referring to is a session. concrete5's sessions involve these statments:

// create the session,  or retrieve the existing one
$session = Core::make('app')->make('session');
// Get a variable from the session
$var = $session->get('MyVar');
// Remove a session value
$session->remove('MyVar');
// Save a session value
$session->set('MyVar', $value);


$value can be anything you like - a string, a number or an array or even an object.

However when working with sessions or indeed any user input, you need to be extremely sure that anything you save is sanitised first, otherwise you potentially open up security holes. Never trust what the user sends you.

You should then be able to read and write session info from wherever you need to, whether that's a block or a page.
pzg replied on at Permalink Reply
Thank you for the reply Jero! I will give it a try....

-Stephan