Highlighted

How to capture values from referrer?

Engaged ,
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.

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>

Views

731

Likes

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

How to capture values from referrer?

Engaged ,
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.

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>

Views

732

Likes

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
Feb 09, 2016 0
Most Valuable Participant ,
Feb 09, 2016

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Feb 09, 2016 0
Engaged ,
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.

Likes

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
Reply
Loading...
Feb 09, 2016 0
Most Valuable Participant ,
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?

Likes

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
Reply
Loading...
Feb 09, 2016 0
Engaged ,
Feb 09, 2016

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Feb 09, 2016 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Feb 09, 2016 0
Engaged ,
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.

Likes

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
Reply
Loading...
Feb 09, 2016 0
LEGEND ,
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,

^_^

Likes

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
Reply
Loading...
Feb 09, 2016 2
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Feb 09, 2016 0
Engaged ,
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

Likes

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
Reply
Loading...
Feb 15, 2016 0
Engaged ,
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>

Likes

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
Reply
Loading...
Feb 15, 2016 0