Lesson 12 | Clearing cookies |
Objective | Identify the steps involved in clearing a cookie |
Clearing Cookies in Perl
In order to clear a cookie, you simply expire it. In Netscape cookies, that means setting the Expires date to a date in the past:
Set cookie: UserID=007; Expires=Mon, 01-Jan-1990 00:00:00 GMT
In RFC-2109 cookies, you set the Max-Age value to zero:
Set cookie: UserID=007; Max-Age=0; Version=1
This does not work in the current beta of Netscape 4. As of this writing, RFC-2109 is still being debated by the members of the Internet Engineering Task Force, HTTP Working Group. For that reason, all the examples in this module use the Netscape cookies which are supported by a large number of browsers currently available.
Cookie example
The
cookies.cgi is a simple example of setting and clearing cookies. The source code is available for download from the course Resources page.
Notice the use of an intermediate screen to inform users that the cookie is being saved. The purpose of that screen is really twofold:
- It gives the system a chance to complete the full round-trip necessary to set the cookie and get a copy of it back.
- It gives users some feedback that something happened when they pushed the Submit button.
ClearPerl - Cookie - Exercise
Obviously, you can have it say something else if you wish. Click the Exercise button to experiment with the cookies.cgi program.
Clear Perl Cookie - Exercise