Difference between global and session variables

Hi
i was wondering about differences between global and session variables
in SC doc it is not really clear what are the consequences/real difference.
any security differences or other ?

Global variables are only valid within the scope of the module you are running, not outside. Session variables are bound to a session ($_SESSION) which means that they are shared over your modules. Then you have get and post which you should avoid due to security issues. Again, a long time discussion with SC, as I believe that session should be default.

1 Like

I was always assuming global variables are also stored in the session on the server , where are the values are stored if not in the session?
could you elaborate what you call modules?
i can use a global variable across apps, i assume you mean by modules something else?
thank Albert

I guess that all are stored in the session, you can verify it printing the $_SESSION variable, if I recall correctly global variables are stored as _SESSION['scriptcaseì][‘globalvar’], while module variables are stored as _SESSION['scriptcaseì]['modulenameì][‘variablname’], or something like that, I don’t check those things since months.

1 Like

I have to disagree partially on what Albert says.

A Scriptcase global variable [myvar] is saved into PHP session and is accessible to ALL modules (apps) sharing the same session.
As soon as a global variable is assigned (regardless is declared as GET,POST or SESSION, and this is another big source of confusion) it is saved into the PHP session.
A module variable (called attribute in SC language {myvar}) is also saved into PHP session but is kept separate among modules (e.g. you can have two modules using the same name for an attribute and the corresponding values are kept separate).

Keep in mind that global and module variables, being saved in the PHP session, are accessible to all PHP scripts sharing the same session, regardless are written in SC or not, using $_SESSION array.

$_SESSION[‘myvar’] and SC global [myvar] and SC attribute {myvar} are all saved in PHP session but in different places so the three values are kept separate.

Due to the way PHP sessions work, if you don’t want that a SC global variable is shared among different apps you need to make sure that each app runs in a separate session (e.g. apps need to be accessed with different host names)

3 Likes

Thank you. I can’t always be right.

3 Likes

Come on Albert you are a star in this forum !

4 Likes