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.
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.
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)
Thank you. I can’t always be right.
Come on Albert you are a star in this forum !
I was wondering if attributes can be used in the queries as well or be pathed through on opening of an app? otherwise besides sharing variables among the events I do not see a practical value .
If attributes could stick to each open instance of an app that would be great. right now it is a problem to open multiple instances of the same app with different filters if a global variable used in the query where.
it would indeed more useful if global variables could stick to each open instance of the app, and session variables be true global among the apps.
-
You can use attributes in an SQL query by using the
sc_select_where(add)
macro in theOnScriptInit
event. -
The practical advantage of attributes is that they are local to the app and do not get mixed up across different apps like GlobalVars do.
-
Global variables and attributes are ultimately saved in the PHP session. Therefore, if you need to open several instances of the same app, one way to keep the sessions separate is to use different URLs. For example:
http://myserver1/MyApp.php
,http://myserver2/MyApp.php
, andhttp://myserver3/MyApp.php
will open three instances of MyApp, and each instance will remain well-separated from the others.