CURLINFO_REFERER(3)

πŸ’… CURLINFO_REFERER β€” bestie, let's peek at your HTTP referrer ✨

okay so this is CURLINFO_REFERER, a libcurl thing, straight out of the Library Functions Manual. it's the little incantation you use to find out what referrer header got sent, no cap πŸŽ€


✨ NAME ✨

CURLINFO_REFERER β€” the option that grabs the used HTTP referrer request header. that's it, that's the whole vibe πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_REFERER, char **hdrp);

like, look at her. three args, zero drama 🫢


🌸 DESCRIPTION 🌸

so here's the tea: you pass in a pointer to a char pointer, and the function hands you back the referrer header used in the most recent request. that's literally it. main character info retrieval πŸ’…

now the important part, bestie, do not skip this:

  • the hdrp pointer is either NULL or it points to private memory
  • you must not free it β€” nope, not yours, hands off πŸ™ˆ
  • that memory gets freed automatically when you call curl_easy_cleanup(3) on the corresponding curl handle. it's giving built-in cleanup, iykyk ✨

🌈 PROTOCOLS 🌈

this functionality affects http only. that's the whole section. periodt. 🧚


🌟 EXAMPLE 🌟

here's the actual code, copied exactly because we don't play with literals πŸ‘‘

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
    curl_easy_setopt(curl, CURLOPT_REFERER, "https://example.org/referrer");
    result = curl_easy_perform(curl);
    if(result == CURLE_OK) {
      char *hdr = NULL;
      curl_easy_getinfo(curl, CURLINFO_REFERER, &hdr);
      if(hdr)
        printf("Referrer header: %s\n", hdr);
    }
    curl_easy_cleanup(curl);
  }
}

so you init the handle, set CURLOPT_URL to "https://example.com", set CURLOPT_REFERER to "https://example.org/referrer", perform the request, and if it came back CURLE_OK you grab the header into hdr and print it with printf("Referrer header: %s\n", hdr). then curl_easy_cleanup because we're responsible besties πŸŽ€ and yes the if(hdr) check is there, we stan a NULL check πŸ’œ


πŸ¦‹ AVAILABILITY πŸ¦‹

added in curl 7.76.0. if your curl is older than that, this vibe check fails, sorry 😭


πŸ’€ RETURN VALUE πŸ’€

curl_easy_getinfo(3) returns a CURLcode that's either success or error, no in-between bestie:

  • CURLE_OK (0) β€” everything was OK, we ate πŸ”₯
  • non-zero β€” an error occurred, and you should go see libcurl-errors(3) for the details

πŸŽ€ SEE ALSO πŸŽ€


reminder bestie: do not free the memory you get back from CURLINFO_REFERER. curl_easy_cleanup(3) handles that. free it yourself and you'll be in undefined-behaviour territory, which is not the slay you want πŸ’€

okay that's the whole page, ily, go grab your referrer headers responsibly πŸ’–βœ¨

β€” written by the libcurl girlies, libcurl, dated 2026-10-12, and that's the CURLINFO_REFERER(3) page, periodt 🫢🌸

πŸ“¦ where this page comes from