xref: /curl/docs/libcurl/opts/CURLINFO_REFERER.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLINFO_REFERER
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_REFERER (3)
9  - curl_easy_getinfo (3)
10  - curl_easy_header (3)
11  - curl_easy_setopt (3)
12Protocol:
13  - HTTP
14Added-in: 7.76.0
15---
16
17# NAME
18
19CURLINFO_REFERER - get the used referrer request header
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_REFERER, char **hdrp);
27~~~
28
29# DESCRIPTION
30
31Pass in a pointer to a char pointer and get the referrer header used in the
32most recent request.
33
34The **hdrp** pointer is NULL or points to private memory you MUST NOT free -
35it gets freed when you call curl_easy_cleanup(3) on the corresponding
36CURL handle.
37
38# %PROTOCOLS%
39
40# EXAMPLE
41
42~~~c
43int main(void)
44{
45  CURL *curl = curl_easy_init();
46  if(curl) {
47    CURLcode res;
48    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
49    curl_easy_setopt(curl, CURLOPT_REFERER, "https://example.org/referrer");
50    res = curl_easy_perform(curl);
51    if(res == CURLE_OK) {
52      char *hdr = NULL;
53      curl_easy_getinfo(curl, CURLINFO_REFERER, &hdr);
54      if(hdr)
55        printf("Referrer header: %s\n", hdr);
56    }
57    curl_easy_cleanup(curl);
58  }
59}
60~~~
61
62# %AVAILABILITY%
63
64# RETURN VALUE
65
66Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
67