1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_COOKIEFILE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_COOKIE (3)
9  - CURLOPT_COOKIEJAR (3)
10  - CURLOPT_COOKIESESSION (3)
11Protocol:
12  - HTTP
13Added-in: 7.1
14---
15
16# NAME
17
18CURLOPT_COOKIEFILE - filename to read cookies from
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEFILE, char *filename);
26~~~
27
28# DESCRIPTION
29
30Pass a pointer to a null-terminated string as parameter. It should point to
31the filename of your file holding cookie data to read. The cookie data can be
32in either the old Netscape / Mozilla cookie data format or just regular HTTP
33headers (Set-Cookie style) dumped to a file.
34
35It also enables the cookie engine, making libcurl parse and send cookies on
36subsequent requests with this handle.
37
38By passing the empty string ("") to this option, you enable the cookie engine
39without reading any initial cookies. If you tell libcurl the filename is "-"
40(just a single minus sign), libcurl instead reads from stdin.
41
42This option only **reads** cookies. To make libcurl write cookies to file,
43see CURLOPT_COOKIEJAR(3).
44
45If you read cookies from a plain HTTP headers file and it does not specify a
46domain in the Set-Cookie line, then the cookie is not sent since the cookie
47domain cannot match the target URL's. To address this, set a domain in
48Set-Cookie line (doing that includes subdomains) or preferably: use the
49Netscape format.
50
51The application does not have to keep the string around after setting this
52option.
53
54If you use this option multiple times, you add more files to read cookies
55from. Setting this option to NULL disables the cookie engine and clears the
56list of files to read cookies from.
57
58# SECURITY
59
60This document previously mentioned how specifying a non-existing file can also
61enable the cookie engine. While true, we strongly advise against using that
62method as it is too hard to be sure that files that stay that way in the long
63run.
64
65# DEFAULT
66
67NULL
68
69# %PROTOCOLS%
70
71# EXAMPLE
72
73~~~c
74int main(void)
75{
76  CURL *curl = curl_easy_init();
77  if(curl) {
78    CURLcode res;
79    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
80
81    /* get cookies from an existing file */
82    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookies.txt");
83
84    res = curl_easy_perform(curl);
85
86    curl_easy_cleanup(curl);
87  }
88}
89~~~
90
91# Cookie file format
92
93The cookie file format and general cookie concepts in curl are described
94online here: https://curl.se/docs/http-cookies.html
95
96# %AVAILABILITY%
97
98# RETURN VALUE
99
100Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
101