Search code examples
curlhttp-referer

is referer stripped to domain name?


cURL offers an option of setting a referer.

curl_setopt($ch, CURLOPT_REFERER, "somestring");

I've been puzzled by to what is referer set, when a webpage is opened via google. For example, I enter stack overflow into google.com and than click first result. The google page from which I opened SO may look like this:

https://www.google.com/search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&q=stack%20overflow&oq=stack%20overflow&aqs=chrome..69i57j19i60l3j69i65j0.2222j0j7

but is that also the referer? Is referer stripped to only google.com? What about if the URL is entered directly into the URL bar at the top if the browser. To what will referer be set than?


Solution

  • The HTTP referer (originally a misspelling of referrer) is an HTTP header field that identifies the address of the webpage (i.e. the URI or IRI) that linked to the resource being requested.

    In a browser the referer is set by the browser. If you visit Google (using your example), and click a link, a GET request is made to the link/server and the referer would be set to:

    https://www.google.com/search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&q=stack%20overflow&oq=stack%20overflow&aqs=chrome..69i57j19i60l3j69i65j0.2222j0j7
    

    The referer is URL of the page that refered you to whatever link you clicked. Referer is used for all types of HTTP request (GET, POST, PUT etc). It can be a fully qualified domain name, or an IP address.

    With a cURL request, no referrer is set if you do not set the CURLOPT_REFERRER. Some web applications require the referer for various pages, thus it would need to be set. Not in all cases though.

    If a URL is entered directly into the address bar, no referer is set because the request has no referer link. Nothing refered it.

    More info: HTTP Referer