Cookies' functions
The Cookies are small files that are recorded on the clients' machines from a web site. The aim is to provide functions that allow reading and recording cookies from the Web Panels generated by GeneXus.
Introduction
The aim is to allow functions that allow reading and recording cookies from the Web Panels generated by GeneXus.
What are the cookies?
The Cookies are small files that are recorded in the clients' machines from a web site. The CGI programs or any application that runs on a server can read or record the cookies in the client. The cookies' commonest use is the users' identification. When a user registers on a web site (Portal or E-Store), the site records a cookie in the client's machine with the client's identification. This way, the next time that the client visits this site, it tries to read the cookie and if it exists it uses the cookie's value to identify the user and recover his preferences from a database.
There are also other uses that the cookies have, like rotating the contents (specially advertisements), maintaining an application's status, etc. They can even be used as a method for storing the "purchase trolley" in such a way that its information stays in the client's machine and it is maintained among connections.
As we were saying a cookie is generally used to identify the user (in some cases, one for the session, and in some other cases for the user), although all the preferences' values could be put in cookies. The ideal thing is to have a key that travels and to read the user's information with this key.
This way, the user's information does not travel to the client, and it is not in the URL (e.g.: credit cards, name, address). It simply remains in the server.
We have to take into account that there is a limit regarding the quantity of cookies that the client can accept. The maximum are 300 cookies in total per client (for all the servers together per each browser/client) and 20 cookies per server or domain, which means that if an application records more than 20 cookies, the last ones are going to erase the first ones' values.
There is also a size limit of 4K per cookie. If a cookie goes over that limit it is trenched.
The user may prefer not recording the cookie permanently (for example, if you are accessing from a public machine) or he may even disable the use of cookies, so it must not be the only way to identify the user and there has to be an alternative method in case that the browser does not support or does not have the cookies' management enabled.
Another thing is that the place where the cookies are stored (at least in Windows) depends on the browser, so if a user has more than one browser, each of them will have an independent set of cookies.
A Cookie's life cycle is:
1. The user gets connected to a server that for some reason wants to record a cookie.
2. In the answer (HTML Headers), you indicate the name and the value of the cookie to be recorded, as well as other values (the most relevant one is the expiration date).
3. The browser receives the answer and, if the value of the expiration date is in the future it records it; if not, it looks for one with that name and erases it.
4. Every time the user gets connected to a URL of this domain the browser will send the cookies that have been recorded from the domain and have not expired to the server.
5. Once the expiration date has been passed, the cookies are erased.
In order to get more technical information about cookies and their use: http://www.cookiecentral.com
In the next issue we will explain the functions that are available in GeneXus to work with cookies.