KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Cookies and 4D v6.5
PRODUCT: 4D | VERSION: | PLATFORM:
Published On: June 4, 1999

Cookies allow a Web Server to save and retrieve information on a Web Browser client. Each time a browser makes a request of the server, it can send the contents of the cookie in the HTTP header. The server can then use and update the cookie as necessary. Cookies can be used in a multitude of ways. For instance, they can be used to identify users, set preferences, save shopping carts, log user habits, customize start pages, target advertising, and so on.

The new command SET HTTP HEADER in 4D v6.5 allows 4D to create and manage cookies. By using SET HTTP HEADER, you can define the fields within the HTTP header of the response sent to the Web browser by 4D. Since cookies are encapsulated in the header, 4D gives you complete control to create and modify cookies.

One way to manage information from cookies is to create a special 4D table. When the web client requests a file for the first time, set a cookie. To identify the cookie, place a unique long integer in one of the cookie's fields. Create a record in the 4D cookie table with the corresponding long integer. Whenever the client issues another request, the long integer, or cookie, is sent back to the server. The server can query the record in the cookie table and respond accordingly.

There is a standard format for HTTP headers for which your syntax will need to comply. The information on HTTP header syntax can be found at https://www.w3c.org.

Note: SET HTTP HEADER works only in non-contextual mode.