Example

This example show a typical login form with a "remember" checkbox.

File cookies.xcf
<APPLICATION Parent="defaultgwc" ...>
   <RESOURCE Id="apppath" Source="INTERNAL">C:\path-to-folder\cookie-example
   </RESOURCE>
   
   <EXECUTION>
     <PATH>$(apppath)</PATH>
     <MODULE>cookies.42r</MODULE>
   </EXECUTION>
   <OUTPUT>
     <HTTP_COOKIES>
        <HTTP_COOKIE Id="cookies" Expires="Mon, 30-Sep-2009 23:59:59 GMT" 
           Secure="FALSE" HttpOnly="TRUE" >
           <VARIABLE Id="login" />
        </HTTP_COOKIE>
     </HTTP_COOKIES>
   </OUTPUT>
</APPLICATION>
File cookies.4gl
DEFINE login, password STRING 
DEFINE rememberme SMALLINT 
DEFINE result INTEGER 
DEFINE test STRING 
MAIN
   
   OPEN WINDOW w WITH FORM "cookies"
   
   # Get the login cookie
   CALL ui.Interface.FrontCall("session","getvar",["login"], [login])
   MESSAGE SFMT("Cookie retrieved %1", login)
   CALL ui.Interface.Refresh()
   SLEEP 2
   
   INPUT login, password, rememberme
      WITHOUT DEFAULTS FROM
        login, password, rememberme
      
      
      AFTER INPUT
         IF int_flag THEN
            EXIT INPUT
         END IF
      IF rememberme THEN
         # Set the login cookie
         CALL ui.Interface.FrontCall("session","setvar",
          ["login",login],result)
         MESSAGE SFMT("Cookie %1 set with result %2", login, result)
         CALL ui.Interface.Refresh()
         SLEEP 2
         
         #Test that we can get the login cookie back
         CALL ui.Interface.FrontCall("session","getvar","login",test)
         MESSAGE SFMT("Test Cookie get, value is %1", test)
         CALL ui.Interface.Refresh()
         SLEEP 2
      END IF
   END INPUT 

END MAIN
File cookies.per
LAYOUT 
GRID
{
Login   [f01          ]
Password [f02         ]

Remember Me [f03]
}
END 
END 
ATTRIBUTES 
f01 = formonly.login; 
f02 = formonly.password, INVISIBLE; 
CHECKBOX f03 = formonly.rememberme,NOT NULL; 
END