• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to capture values from referrer?

Enthusiast ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

Is there a way to capture the value passed in the referrer? I need to capture that and do some searching.

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Feb 15, 2016 Feb 15, 2016

Okay, so all I have to do to get the URL parameter value is URL.variable name.

<cfhttp url="https://app.knowledgeowl.com/api/head/article.json" method="get" timeout="15">

  <cfhttpparam type="url" name="_authbykey" value="56a7d8c532131c4058362589">

    <cfhttpparam type="url" name="project_id" value="55c4ffd258561c527e294fe6">

    <!---<cfhttpparam type="url" name="url_hash" value="calendar">--->

    

     <!--- Pass along any URL values. --->

     <cfhttpparam type="url" name="url_hash" value="#URL.

...

Votes

Translate

Translate
Guide ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

Can you elaborate a what "value" you are talking about?  Please be specific.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

I guess I can use <cfdump var="#CGI#"> to show and then get my values from the QUERY_STRING.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

Possibly.  But keep in mind that dumping the CGI scope won't necessarily reveal every attribute available. Depending on the web server you are using, it may populate CGI variables that don't show in CFDUMP - you just have to know what they are and access them directly (as CGI.some_obscure_variable).

What referrer information are you looking for?  From my local CF10 development environment, it looks like the CGI.HTTP_REFERER variable contains the full URL (including query string) from the referring page.  Is that what you were looking for?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

I'm looking for the parameter value that's being passed from the previous page.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

Again, can you be specific?  What parameter are you referring to?  A URL parameter?  If so, it will likely be in the CGI.HTTP_REFERER variable, but you'll have to parse the whole URL to find the parameter you are looking for.  This CFLib function might help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

In the Referrer it looks like this: https://www.mysite.com/search/?search=basics and I want to get the value of the parameter "search". In this case the value is "basics". I don't know if this is through the URL or not but this is what is showing under the Net/XHR/Headers in firebug.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

If you take the URL and treat it like a list with '?' as the delimiter, using the second index you'll get "paramName=paramValue".  Take this value and (again) treat it like a list with '=' as the delimiter, you'll get index1 as the parameter name and index2 as the value.

This is assuming that there is only ONE URL parameter passed.  If there are more than one, you'll have to insert another process to see a list using '&' as the delimiter.  The downside to that is that any value having a '&' in it will give a false indication of where the list actually is.

HTH,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 09, 2016 Feb 09, 2016

Copy link to clipboard

Copied

I think the CFLib function I provided a link for does all of what WolfShade‌ mentioned for you. Essentially, you pass it the full URL (like https://mysite.com/search/?search=basics) and the parameter name you are looking for (like "search") and it will return the parameter's value (like "basics").

Here are some other related and useful UDFs from CFLib.org:

CFLib.org – splitUrl

CFLib.org – QueryStringChangeVar

CFLib.org – QueryStringDeleteVar

-Carl V.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 15, 2016 Feb 15, 2016

Copy link to clipboard

Copied

Carl,

I'm trying out the function you posted above and for some reason it's returning blank. Below is my code:

<cfhttp url="https://app.knowledgeowl.com/api/head/article.json" method="get" timeout="15">

  <cfhttpparam type="url" name="_authbykey" value="56a7d8c123131c4058361789">

    <cfhttpparam type="url" name="project_id" value="55c4ffd456131c527e7899fe6">

    <!---<cfhttpparam type="url" name="url_hash" value="calendar">--->

    

     <!--- Pass along any URL values. --->

    

     <cfhttpparam type="url" name="url_hash" value="#queryStringGetVar(CGI.http_referer, 'slug')#" />

     <cflog text="URL-Hash: #queryStringGetVar(CGI.http_referer, 'slug')#" type="Information" file="CGIparameters">

  

</cfhttp>

<cfscript>

  /**

* Gets the value of a variable in a query string.

*

* @param query_string The query string to examine. (Required)

* @param this_var_name The variable to look for. (Required)

* @return Returns a string.

* @author Shawn Seley (shawnse@hotmail.com)

* @version 1, August 1, 2005

*/

  function queryStringGetVar(querystring, this_var_name){

  var re_found_struct = "";

  querystring = trim(querystring);

  re_found_struct = REFindNoCase("(^|[\?|&])#this_var_name#=([^\&]*)", querystring, 1, "true");

  // = re_found_struct.len & re_found_struct.pos

  if(arrayLen(re_found_struct.pos) gte 3) {

  if (re_found_struct.pos[3] GT 0) return urlDecode(mid(querystring, re_found_struct.pos[3], re_found_struct.len[3]));

  else return "";

  } else return "";

  }

</cfscript>

The log shows blank. So, I'm not quite sure why. The CGI.http_referrer shows this: https://devbox.mysite.com/kb/?slug=calendar

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 15, 2016 Feb 15, 2016

Copy link to clipboard

Copied

Okay, so all I have to do to get the URL parameter value is URL.variable name.

<cfhttp url="https://app.knowledgeowl.com/api/head/article.json" method="get" timeout="15">

  <cfhttpparam type="url" name="_authbykey" value="56a7d8c532131c4058362589">

    <cfhttpparam type="url" name="project_id" value="55c4ffd258561c527e294fe6">

    <!---<cfhttpparam type="url" name="url_hash" value="calendar">--->

    

     <!--- Pass along any URL values. --->

     <cfhttpparam type="url" name="url_hash" value="#URL.slug#" />

     <cflog text="URL-Hash: #URL.slug#" type="Information" file="CGIparameters">

  

</cfhttp>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

Hello - we are currently getting the domain of the referrer. This is working. We need help getting the full path of the referring url. 

 

For example...

 

Lets say someone comes from google using this search

https://www.google.com/search?q=tax+preparation+08816&rlz=1C1CHBF_enUS859US859&oq=tax+pre&aqs=chrome...

 

We are already getting:

https://www.google.com/

 

but how do we go about getting the rest of that string?

search?q=tax+preparation+08816&rlz=1C1CHBF_enUS859US859&oq=tax+pre&aqs=chrome.1.69i57j35i39j69i65l3j...

 

or just

search?q=tax+preparation+08816

 

Next example:

https://antonuccilegal.com/blog/new-jersey-auto-insurance-consumers-have-rights/

 

If this was referrer url, we would get...

https://antonuccilegal.com/

but we want full path

https://antonuccilegal.com/blog/new-jersey-auto-insurance-consumers-have-rights/

 

We are running Coldfusion 2016 and need some guidance.

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

LATEST

You cannot rely on the referrer value. It's not guaranteed to have a useful value.

The User Agent (Web browser) controls what value you will see and it will be different for each of your visitors depending on their User Agent and its settings.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation