0
UDF
Participant
,
/t5/coldfusion-discussions/udf/td-p/498492
Oct 23, 2007
Oct 23, 2007
Copy link to clipboard
Copied
I am trying to implement my first udf
http://www.cflib.org/udf.cfm?id=585&enable=1
which list the keywords received in a cgi.http_referer but I
don´t understand it properly.
I have the udf on one page saved as a .cfm which is included on the Application.cfm (please see UDF code below)
My script which I put on the same page is here:
<cfset greferer= cgi.http_referer>
<cfoutput>
Keywords from #referer# = #GetGoogleKeywords(greferer)#<br>
</cfoutput>
How do I implement this rigth? Thank you
UDF:
<cfscript>/*
** Pass it a http_referer value and this fuction will parse out the keywords used to find it if referred from Google.
*
* @Param referer The referer string to check. (Required)
* @Return Returns a string.
* @author Matthew Fusfield (matt@fus.net)
* @version 1, June 28, 2002
*/
function getGoogleKeywords(referer) {
var Keywords='';
var StartPos=0;
var EndString='';
if (referer contains 'google.com') {
StartPos=ReFindNoCase('q=.',referer);
if (StartPos GT 0) {
EndString=mid(referer,StartPos+2,Len(referer));
Keywords=ReReplaceNoCase(EndString,'&.*','','ALL');
Keywords=URLDecode(Keywords);
}
return Keywords;
}
else {
return '';
}
}</cfscript>
I have the udf on one page saved as a .cfm which is included on the Application.cfm (please see UDF code below)
My script which I put on the same page is here:
<cfset greferer= cgi.http_referer>
<cfoutput>
Keywords from #referer# = #GetGoogleKeywords(greferer)#<br>
</cfoutput>
How do I implement this rigth? Thank you
UDF:
<cfscript>/*
** Pass it a http_referer value and this fuction will parse out the keywords used to find it if referred from Google.
*
* @Param referer The referer string to check. (Required)
* @Return Returns a string.
* @author Matthew Fusfield (matt@fus.net)
* @version 1, June 28, 2002
*/
function getGoogleKeywords(referer) {
var Keywords='';
var StartPos=0;
var EndString='';
if (referer contains 'google.com') {
StartPos=ReFindNoCase('q=.',referer);
if (StartPos GT 0) {
EndString=mid(referer,StartPos+2,Len(referer));
Keywords=ReReplaceNoCase(EndString,'&.*','','ALL');
Keywords=URLDecode(Keywords);
}
return Keywords;
}
else {
return '';
}
}</cfscript>
TOPICS
Getting started
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/coldfusion-discussions/udf/m-p/498493#M45280
Oct 23, 2007
Oct 23, 2007
Copy link to clipboard
Copied
From your question, the following is what I would suggest,
please post back if not suitable.
For ease, I would out the funciton in the request scope by having the following line directly after the UDF above:
request.getGoogleKeywords = getGoogleKeywords;
Then, on any page you want to use it, just have the following:
thisGoogleKeyWords = request.getGoogleKeyWords(CGI.HTTP_REFERRER);
This will then give you a list of the Google keywords that were used to access the page to do what you want with on that page (ie highlighting).
By including the CFM template that contains the UDF in the Application.cfm it will then be available to any other template via the request scope.
Couple of caveats:
1. Not exactly best Software Engineering practice, but lets get it working first.
2. CGI.HTTP_REFERRER is sometimes blank depending on the Web Server/Application Server/Browser so do _not_ make it essential that it is present
3. Above is rough, you need to give more information about what you want to actually do with the function if that doesn't give you a starter (you do know why you want to see the Google Keywords from the referrer, right?)
For ease, I would out the funciton in the request scope by having the following line directly after the UDF above:
request.getGoogleKeywords = getGoogleKeywords;
Then, on any page you want to use it, just have the following:
thisGoogleKeyWords = request.getGoogleKeyWords(CGI.HTTP_REFERRER);
This will then give you a list of the Google keywords that were used to access the page to do what you want with on that page (ie highlighting).
By including the CFM template that contains the UDF in the Application.cfm it will then be available to any other template via the request scope.
Couple of caveats:
1. Not exactly best Software Engineering practice, but lets get it working first.
2. CGI.HTTP_REFERRER is sometimes blank depending on the Web Server/Application Server/Browser so do _not_ make it essential that it is present
3. Above is rough, you need to give more information about what you want to actually do with the function if that doesn't give you a starter (you do know why you want to see the Google Keywords from the referrer, right?)
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Hydrowizard
AUTHOR
Participant
,
LATEST
/t5/coldfusion-discussions/udf/m-p/498494#M45281
Nov 04, 2007
Nov 04, 2007
Copy link to clipboard
Copied
Thank you for the reply dacf I am confused as to where to put
the cfscript:
this code:
request.getGoogleKeywords = getGoogleKeywords;
Then, on the page I want to use it how do I output this?
thisGoogleKeyWords = request.getGoogleKeyWords(CGI.HTTP_REFERRER);
TIA
this code:
request.getGoogleKeywords = getGoogleKeywords;
Then, on the page I want to use it how do I output this?
thisGoogleKeyWords = request.getGoogleKeyWords(CGI.HTTP_REFERRER);
TIA
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

