ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Web-specific functions / Browser functions
  • Example 1: Checking whether the browser accepts the cookies
  • Example 2: Writing and reading a cookie
CookieRead (Example)
Example 1: Checking whether the browser accepts the cookies
WEBDEV - Browser codePHP This example is used to check whether the current browser accepts the cookies.
// -- Button/Link with "no" server action, browser onclick event
// Checks whether the cookies are accepted by the browser
 
// Write a cookie in a browser code
sCookieVal is string
sCookieVal = DateSys() + TimeSys()
CookieWrite("TestCookieAccepted", sCookieVal)
// Re-read the cookie and check the value read
IF NOT sCookieVal = CookieRead("TestCookieAccepted") THEN
// Cookies not accepted
Error("The browser does not accept the cookies", ...
"Modify the parameters of your browser" + ...
"to accept the cookies.")
ELSE
// Cookies accepted
Info("Cookies accepted")
END
Example 2: Writing and reading a cookie
WEBDEV - Server codePHPAjax The following code writes a cookie in server code to indicate the last use. At the end of the server code, when going back to the browser, the cookie will be updated in the browser of the Web user.
A single cookie can be written per server process.
The cookie can be read in another session (and only in another session).
// -- Click on a button/link (server code)
// Write a cookie in server code
CookieWrite("LastUse", DateSys() + TimeSys())
This example is used to read, in server code, the value of a cookie of a previous session.
// Read a cookie in server code
// CookieRead can only be used to
// read the cookies loaded in memory at the beginning of the session.
// Therefore, the cookies written in the current session cannot be read.
 
// The cookie must have been written during a previous session
sCookieVal is string
sCookieVal = CookieRead("LastUse")
IF NOT sCookieVal ~= "" THEN
Info("The last use is: ", sCookieVal)
END
Minimum version required
  • Version 16
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help