---
name: "cgiGetCookie"
section: "3"
platform: "linux"
package: "cgilib"
version: "0.6-1.1+b1"
release: "Debian 11 (Bullseye)"
platforms: ["linux"]
url: "https://new.carta.tech/cgiGetCookie"
---

# cgiGetCookie(3)

Return a cookie

## NAME

cgiGetCookie - Return a cookie

## SYNOPSYS

```
#include <cgi.h>

s_cookie *cgiGetCookie (s_cgi *parms, const char *name);
```

## DESCRIPTION

This routine returns a pointer to a s\_cookie structure that contains all values for the cookie as referenced by *name*. The pointer must not be freed.

The *s\_cookie* structure is declared as follows:

```
typedef struct cookie_s {
    char     *version,
             *name,
             *value,
             *path,
             *domain;
} s_cookie;
```

Memory allocated by this data structure is automatically freed by the final call to [**cgiFree**(3)](/cgiFree/3.md).

To set a cookie in your program you'll need to manually add additional header lines.  Please take a look at *cgitest.c*. Basically, you'll need to add the following code:

```
   cgiSetHeader ("Set-Cookie", "Version=1; name=value; Path=/");
   cgiHeader();
```

Please read the included file *cookies.txt* as well.

## RETURN VALUE

On success a pointer to a s\_cookie structure is returned.  If no cookie was set or no cookie with a given name exists NULL is returned.

## AUTHOR

This CGI library is written by Martin Schulze \<joey@infodrom.org\>.  If you have additions or improvements please get in touch with him.

## SEE ALSO

[**cgiGetValue**(3)](/cgiGetValue/3.md), [**cgiGetVariables**(3)](/cgiGetVariables/3.md), [**cgiGetCookies**(3)](/cgiGetCookies/3.md), [**cgiDebug**(3)](/cgiDebug/3.md), [**cgiHeader**(3)](/cgiHeader/3.md), [**cgiInit**(3)](/cgiInit/3.md), [**cgiFree**(3)](/cgiFree/3.md).
