Search:  

Using cookies

What is a cookie?

Cookies are small amounts of information stored on a user’s computer, that are passed to the webserver with every page request.

Cookies are used to allow users to login to a site: when a user logs in a cookie is stored on their machine, which allows them to be authenticated as they visit subsequent pages on the site. Without cookies, they would need to repeatedly login on every page – which would not be very popular!

In addition to the built-in cookies used by the system, you can store any number of extra cookie to persist user choices.

Whilst this feature does not require any technical knowledge about cookies themselves, you do need to be aware when cookies are stored, and when they are acted upon:


An example:

Imagine a situation where a site needs to remember a user’s language preference.

  1. The first page is a choice page – it shows a list of languages, and the user clicks on one of them.
  2. The second page confirms their choice, and stores this as a cookie on the user’s machine.
  3. Subsequent page requests can use the cookie as the page contents are prepared on the server.


How it works:

The choice: This is a normal embedded query, with a set of links to the confirmation page. The only requirement is that the links can a parameter for the choice to be stored: so in the language example, this would be the Record Id of the language Table. (Example note: You would need to manually create a Table for the language choices – this is not an inherent system table)

The confirmation page needs to contain a query embed, that includes the Record ID of the language table, and has this set as a criteria.

So far, this is no different from any normal choice-confirmation set of queries on two pages.

However we now want the confirmation page to set the cookie. To do this, in the query embed on the confirmation page, against the field with the criteria, check the ‘Save as cookie’ checkbox.

That saves the cookie on the client, and subsequent page requests will have it available to them.

On the subsequent pages, you embed a query on the page, and give it a criteria on the same field. However instead of setting it to use [Page parameters], select [Page parameters, cookies], and it will respect the cookie if there isn’t a page parameter specified.


Notes:

  • Cookies last for the duration of the browser session.
  • To remove a cookie before then, use the Cookie clear component.
  • Cookies are set when a page is loaded, so cannot be set as a result of an Ajax transition – as Ajax transitions do not involve a page load.
  • The cookie is not available to queries on the page which sets the cookie itself, only to subsequent pages.

 


 

Copyright © 2023 Enstar LLC    All rights reserved Print this pageTranslate: