CURLOPT_REFERER(3)

πŸ’… CURLOPT_REFERER β€” the HTTP referer header

okay so bestie, welcome to CURLOPT_REFERER from the Library Functions Manual. yes this is literally the libcurl page for the referer header and no I will not be calm about it πŸŽ€


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_REFERER, char *where);

that's it. that's the whole vibe check. πŸ¦‹


🌸 DESCRIPTION 🌸

so you pass a pointer to a null-terminated string as the parameter, right? and that string is what gets used to set the Referer: header field in the HTTP request you send to the remote server. it's giving "hey bestie, I came from over there" energy πŸ’–

and like β€” you can set any custom header with CURLOPT_HTTPHEADER(3) if you're feeling extra. no gatekeeping here πŸ‘‘

the application does not have to keep the string around after setting this option. so go ahead, let it go, free yourself, it's fine 😌✨

Using this option multiple times makes the last set string override the previous ones. last one wins, no cap, the earlier ones are simply not the main character anymore πŸ’€ and if you set it to NULL you disable its use again. bye bye referer 🫢


πŸŽ€ DEFAULT πŸŽ€

NULL

(default is nothing, we start with nothing, it's a whole blank slate moment πŸ’…)


🌈 PROTOCOLS 🌈

this functionality affects http only. literally just http. that's the whole list. periodt. πŸ“


⭐ EXAMPLE ⭐

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

    /* tell it where we found the link to this place */
    curl_easy_setopt(curl, CURLOPT_REFERER, "https://example.org/me.html");

    curl_easy_perform(curl);
  }
}

look at that comment β€” /* tell it where we found the link to this place */ β€” iconic, self-explanatory, 10/10, no notes 🧚


πŸ¦‹ AVAILABILITY πŸ¦‹

Added in curl 7.1. ancient. vintage. a classic. she's been here since forever and she ate πŸ”₯


πŸ’œ RETURN VALUE πŸ’œ

curl_easy_setopt(3) returns a CURLcode indicating success or error. that's the whole thing, she tells you how it went 🫢

  • CURLE_OK (0) means everything was OK ✨ slay
  • non-zero means an error occurred 😭 see libcurl-errors(3) for the tea

πŸ‘‘ SEE ALSO πŸ‘‘

go read them, they're all besties, iykyk πŸ’–


ngl this page is short and sweet and that's her main character energy. no warnings, no bugs, no drama. just referer. πŸ’…

kisses, this was libcurl, dated 2026-10-12 β€” mwah, see you in the next manpage bestie πŸŒΈπŸŽ€πŸ’œ

πŸ“¦ where this page comes from