Global variables can be used by HEScript, PHP, and JavaScript to share data and store values within the application. Each HEScript script runs in a separate engine, so they cannot share variables directly. To share data between two scripts, for instance, you must use global variables.
You can manage global variables with the following functions:
SetGlobalVarandGetGlobalVarin HEScript.SetGlobalVariableandGetGlobalVariablein JavaScript.exo_setglobalvariableandexo_getglobalvariablein PHP.
Info
Global variables can be used as an alternative to cookies in your JavaScript or PHP code. See the cookies topic for more information.
Properties #
Global variable names must be unique and contain only alphanumeric characters (no spaces). As a general rule, your global variable names should not begin with “HE”, as these are reserved for internal use by ExeOutput for PHP.
Global variables may be persistent or temporary. A persistent variable is stored in the application’s state file, meaning its value is saved and then loaded the next time the application runs. A temporary variable exists only for the current session. You determine whether a variable is persistent when you set its value with the
SetGlobalVarmethod.Global variables are not shared between multiple running instances of an application. However, you can force all instances to have the same global variable values by calling the
SynchronizeGlobalVarHEScript function.
Predefined Global Variables #
Warning
Not all global variables are available in console applications; only HEPublicationFile and HEPublicationPath are used. It is also not possible to change global variable values in console applications.
| Global Variable Name | Description |
|---|---|
HEPublicationFile | The full path to the application’s .exe file (including filename). |
HEPublicationPath | The full path to the folder that contains the application’s .exe file (no filename). It will always include a trailing backslash (e.g., C:\MyPath\). |
HELasterrormessage | When an error occurs, this variable contains the error message. |
DefWinTitle | The title of the main window. |
HomePage | The index page’s filename. |
HEPubStorageLocation | The path where the application stores its data. You can customize it. |
HEPubTempPath | The path to a temporary location where the application stores its external files. This path changes each time the application is run. |
HEPHPDataPath | The path to the virtual cache folder used for PHP files (includes a trailing backslash). |
HEPublicationDiskInfo | Contains the device ID (returned by Windows) of the USB disk on which the application EXE lies. |
CurPageTitle | The title of the page which is currently displayed. |
FwdButtonEnabled | Indicates whether the forward button is enabled (true/false). |
BackButtonEnabled | Indicates whether the back button is enabled (true/false). |
HEMyDocDirectory | Returns the path to the current user’s “My Documents” folder. Does not include a trailing backslash. |
HEStartCurrentDirectory | The working directory when the EXE was launched. Read this global variable instead of calling getcwd() in PHP. |
HEPublicationOnUSB | A boolean (0 or 1) that indicates whether the application is on a USB drive. To use this, GetManualHardwareID(1) must be invoked first. |
isappterminated | Only accessible from PHP. This is set to 1 when the application is terminated. It is useful for breaking infinite loops in PHP. |
hesuppressjsdlg | A boolean (0 or 1) that lets you disable all dialog boxes displayed by JavaScript functions such as alert(). |
PHP Example: Reading a Global Variable #
<?php
$storagelocation = exo_getglobalvariable('HEPubStorageLocation', '');
$file = $storagelocation . 'myfile1.txt';
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");
fclose($fp);
?>HEScript Example #
procedure OnStartMainWindow;
begin
// When the main window is going to be displayed (just before the homepage is shown).
SetGlobalVar("hesuppressjsdlg", "1", false);
end;PHP Loop Example #
For example, you can use this PHP code inside your loops to safely exit:
if (exo_getglobalvariable("isappterminated", "0") == "1") {
break;
}