CGICook - A Irie Pascal sample CGI program

This program is an example of how to process cookies using Irie Pascal CGI programs. A full listing of this program is not given on this page (because it would be too long).

You can download the full source code for this program using the download links at the bottom of this page.

What does CGICook do?

CGICook displays any cookies passed to it, and displays a form that allows the user to add, delete, or modify cookies.

What are Cookies?

Cookies are little pieces of data with names, that a website can send to a browser to be stored. The browser will send this information back to the website every time the user returns to the website. Cookies can be stored for days, weeks, or even years, and are therefore a useful way for websites to "remember" things about visitors.

Setting Cookies

Cookies are set (i.e. created or updated) by sending Set-Cookie: headers to the browser (apparently these headers should precede the Content-Type: header). Set-Cookie: headers look like this:

Set-Cookie: name=value; domain=domainname; path=pathinfo; expires=ExpiryDate; secure


name is the name of the cookie and is required.

value is the value to be stored in the cookie.

domain if given specifies the domains to which the cookie will be sent back to. So for example specifies that the cookie should be sent back to any website in a domain ending with, such as or Notice the leading . in the domain given, which is required. If domain is not given then the cookie will only be sent back to the current website.

path if given must be an absolute path and specifies when the browser should send the cookie back to the website. The URL in the request must match the path given. If path is not specified then it defaults to the full path of the current request.

expires if given specifies when the cookie should expire (and be deleted from the visitor's computer). If expires is not given the cookie expires when the visitor closes the browser.

secure if given specifies that the cookie should only be returned in requests made via https.

An example of a Set-Cookie: header is given below.

Set-Cookie: AcceptsCookies=Y;; path=/cgibin

Reading Cookies

Cookies are returned in the HTTP_COOKIE environment variable, so they can be read using getenv, like any other CGI environment variable.

How does CGICook work?

The main body of the program is shown below (the rest of the program is too long to be shown):


This procedure initializes the program.


This procedure retrieves any form, and cookie data passed to the program. The form data is stored in a global buffer, and the cookie data is stored in a global list.


This procedure reads the form data in the global buffer (if any is there), and formats the data into a Set-Cookie header.


This procedure generates the response and writes it to the standard output stream. Most of the HTML in the response is read from a template file (this allows the use of a HTML editor to create most of the response). The other HTML, that is specific to this program consists of:

  • A Set-Cookie header that adds, deletes, of modifies a cookie.
  • A list of the cookies received from the browser.
  • A form that allows the user to add, delete, and modify a cookie.

This procedure cleans up.

Run CGICook

CGICook has been compiled and installed on this server. To see it run click cookies.cgi.

Download CGICook

Source code: cgicook.pas (size=28,787 bytes).

If you are using the Irie Pascal IDE (available only in the Windows edition) then you should also download the IDE project file: cgicook.ipj (size=1,765 bytes).

Put the source file and the project file in the same directory and open the project file.