1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_COOKIEJAR 5Section: 3 6Source: libcurl 7See-also: 8 - CURLOPT_COOKIE (3) 9 - CURLOPT_COOKIEFILE (3) 10 - CURLOPT_COOKIELIST (3) 11Protocol: 12 - HTTP 13Added-in: 7.9 14--- 15 16# NAME 17 18CURLOPT_COOKIEJAR - filename to store cookies to 19 20# SYNOPSIS 21 22~~~c 23#include <curl/curl.h> 24 25CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIEJAR, char *filename); 26~~~ 27 28# DESCRIPTION 29 30Pass a *filename* as a char *, null-terminated. This makes libcurl write all 31internally known cookies to the specified file when curl_easy_cleanup(3) is 32called. If no cookies are kept in memory at that time, no file is created. 33Specify "-" as filename to instead have the cookies written to stdout. Using 34this option also enables cookies for this session, so if you for example 35follow a redirect it makes matching cookies get sent accordingly. 36 37Note that libcurl does not read any cookies from the cookie jar specified with 38this option. To read cookies from a file, use CURLOPT_COOKIEFILE(3). 39 40If the cookie jar file cannot be created or written to (when the 41curl_easy_cleanup(3) is called), libcurl does not and cannot report an error 42for this. Using CURLOPT_VERBOSE(3) or CURLOPT_DEBUGFUNCTION(3) displays a 43warning, but that is the only visible feedback you get about this possibly 44lethal situation. 45 46Cookies are imported in the Set-Cookie format without a domain name are not 47exported by this option. 48 49The application does not have to keep the string around after setting this 50option. 51 52Using this option multiple times makes the last set string override the 53previous ones. Set it to NULL to disable its use again. 54 55# SECURITY CONCERNS 56 57libcurl cannot fully protect against attacks where an attacker has write 58access to the same directory where it is directed to save files. This is 59particularly sensitive if you save files using elevated privileges. 60 61# DEFAULT 62 63NULL 64 65# %PROTOCOLS% 66 67# EXAMPLE 68 69~~~c 70int main(void) 71{ 72 CURL *curl = curl_easy_init(); 73 if(curl) { 74 CURLcode res; 75 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin"); 76 77 /* export cookies to this file when closing the handle */ 78 curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "/tmp/cookies.txt"); 79 80 res = curl_easy_perform(curl); 81 82 /* close the handle, write the cookies */ 83 curl_easy_cleanup(curl); 84 } 85} 86~~~ 87 88# %AVAILABILITY% 89 90# RETURN VALUE 91 92curl_easy_setopt(3) returns a CURLcode indicating success or error. 93 94CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 95libcurl-errors(3). 96