In
computing
Computing is any goal-oriented activity requiring, benefiting from, or creating computer, computing machinery. It includes the study and experimentation of algorithmic processes, and the development of both computer hardware, hardware and softw ...
, a magic cookie, or just cookie for short, is a token or short packet of data passed between communicating
programs. The cookie is often used to identify a particular
event or as "handle, transaction ID, or other token of agreement between cooperating programs".
Usage
Cookie data is typically not meaningful to the recipient program. The contents are
opaque and not usually interpreted until the recipient passes the cookie data back to the sender or perhaps another program at a later time.
In some cases, recipient programs are able to meaningfully compare two cookies for equality.
The cookie can be used like a
ticket
Ticket or tickets may refer to:
Slips of paper
* Lottery ticket
* Parking ticket, a ticket confirming that the parking fee was paid (and the time of the parking start)
* Toll ticket, a slip of paper used to indicate where vehicles entered a to ...
.
Early use
The term ''magic cookie'' appears in the
man page
A man page (short for manual page) is a form of software documentation found on Unix and Unix-like operating systems. Topics covered include programs, system libraries, system calls, and sometimes local system details. The local host administr ...
for the
fseek
The C (programming language), C programming language provides many standard library subroutine, functions for computer file, file input/output, input and output. These functions make up the bulk of the C standard library header file, header . The ...
routine in the C standard library, dating back at least to 1979, where it was stated:
* "''ftell'' returns the current value of the offset relative to the beginning of the file associated with the named ''stream''. It is measured in bytes on UNIX; on some other systems it is a magic cookie, and the only foolproof way to obtain an ''offset'' for ''fseek''."
[Bell Telephone Laboratories, Incorporated. "FSEEK(3S)." In ''UNIX Time-Sharing System: UNIX Programmer’s Manual'', Revised and expanded version of 7th Edition, Volume 1, page 263. New York: Holt, Rinehart and Winston, 1983. https://archive.org/details/unixtimesharings0001bell]
Cookie as token
An analogy is the token supplied at a coat check (
cloakroom
A cloakroom, known as a coatroom and checkroom in North America, is a room for people to hang their coats, cloaks, canes, umbrellas, hats, or other outerwear when they enter a building. Cloakrooms are typically found inside large buildings, ...
) counter in
real life
Real life is a phrase used originally in literature to distinguish between the real world and fictional, virtual or idealized worlds, and in acting to distinguish between actors and the Character (arts), characters they portray. It has become a ...
. The token has no intrinsic meaning, but its uniqueness allows it to be exchanged for the correct coat when returned to the coat check counter. The coat check token is opaque because the way in which the counter staff are able to find the correct coat when the token is presented is immaterial to the person who wishes their coat returned. In other cases (as is possible with
HTTP cookie
HTTP cookie (also called web cookie, Internet cookie, browser cookie, or simply cookie) is a small block of data (computing), data created by a web server while a user (computing), user is browsing a website and placed on the user's computer o ...
s), the actual data of interest can be stored as name–value pairs directly on the cookie.
Cookies are used as identifying tokens in many computer applications. When one visits a
website
A website (also written as a web site) is any web page whose content is identified by a common domain name and is published on at least one web server. Websites are typically dedicated to a particular topic or purpose, such as news, educatio ...
, the remote server may leave an HTTP cookie on one's computer, where they are often used to
authenticate
Authentication (from ''authentikos'', "real, genuine", from αὐθέντης ''authentes'', "author") is the act of proving an assertion, such as the identity of a computer system user. In contrast with identification, the act of indicating ...
identity upon returning to the website.
Cookies are a component of the most common authentication method used by the
X Window System
The X Window System (X11, or simply X) is a windowing system for bitmap displays, common on Unix-like operating systems.
X originated as part of Project Athena at Massachusetts Institute of Technology (MIT) in 1984. The X protocol has been at ...
.
References
{{Authority control
Data transmission
pl:Cookie