CURLOPT_COOKIESESSION(3)

πŸ’… CURLOPT_COOKIESESSION πŸ’…

okay so this is a page from the Library Functions Manual, bestie β€” CURLOPT_COOKIESESSION β€” and it's literally about starting a brand new cookie session. iykyk πŸͺ✨


🌸 NAME 🌸

CURLOPT_COOKIESESSION β€” start a new cookie session πŸŽ€


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_COOKIESESSION, long init);

πŸ’– DESCRIPTION πŸ’–

so you pass a long set to 1 to mark this as a new cookie "session". what that does, lowkey, is force libcurl to ignore all the cookies it's about to load that are "session cookies" from the previous session. like, ghost them πŸ’€

by default, libcurl always loads all cookies β€” doesn't matter if they're session cookies or not, it's loading them all, no questions asked. and session cookies are the ones without an expiry date, and they're meant to be alive and existing for this "session" only. main character energy but make it temporary 🫢

now, a "session" in browser land is usually defined as, like, as long as you have your browser up β€” more or less. 🌈 and here's the thing: libcurl needs the application to use this option to tell it when a new session starts. otherwise it just assumes everything is still the same session. it's not a mind reader, bestie 😭


πŸŽ€ DEFAULT πŸŽ€

0


πŸ¦‹ PROTOCOLS πŸ¦‹

this functionality affects http only πŸ‘‘


πŸ”₯ EXAMPLE πŸ”₯

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");

    /* new "session", do not load session cookies */
    curl_easy_setopt(curl, CURLOPT_COOKIESESSION, 1L);

    /* get the (non session) cookies from this file */
    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "/tmp/cookies.txt");

    result = curl_easy_perform(curl);

    curl_easy_cleanup(curl);
  }
}

⭐ AVAILABILITY ⭐

added in curl 7.9.7 β€” vintage but iconic πŸ’œ


🧚 RETURN VALUE 🧚

curl_easy_setopt(3) returns a CURLcode indicating success or error β€” that's the vibe check for whether it worked.

CURLE_OK (0) means everything was OK. a non-zero value means an error occurred β€” go see libcurl-errors(3). πŸ™ˆ


🌻 SEE ALSO 🌻


and that's the whole page, bestie!! πŸŽ€ this one came from libcurl and it's dated 2026-10-12 β€” so like, note the date for your records, mwah πŸ’‹βœ¨ slay!

πŸ“¦ where this page comes from