Shawn
asked on
looking to catch the inside and outside link referer in form
what is the best way in CF to get these 2 variables?
Inside link is the last link in the site before filling in the form. eg www.mysite.com/page25.cfm
<input type="Hidden" name="InsideLiink" value="#not sure what would go here#
OutsideLink is the link that brought them to the site. eg for a car company
http://www.google.com/search?hl=en&q=cars&aq=f&oq=
<input type="Hidden" name="OutsideLink" value="#not sure what would go here#
if the link comes from a search engine like google I'd like to parse it into 2 fileds like
SearchEngine = google.com
SearchKeywords = cars
...this last part we could leave for another question if you think it's a little cheeky for one question :)
Inside link is the last link in the site before filling in the form. eg www.mysite.com/page25.cfm
<input type="Hidden" name="InsideLiink" value="#not sure what would go here#
OutsideLink is the link that brought them to the site. eg for a car company
http://www.google.com/search?hl=en&q=cars&aq=f&oq=
<input type="Hidden" name="OutsideLink" value="#not sure what would go here#
if the link comes from a search engine like google I'd like to parse it into 2 fileds like
SearchEngine = google.com
SearchKeywords = cars
...this last part we could leave for another question if you think it's a little cheeky for one question :)
ASKER
found the beginning of Outside link. I put this in the application.cfm
<cfif #HTTP_REFERER# DOES NOT CONTAIN "127.0.0.1" and #HTTP_REFERER# DOES NOT CONTAIN "mysite.com">
<cfset application.OutsideLink = #HTTP_REFERER#>
</cfif>
I can see one problem with this...if in the referer link the mysite.com exists then it won't work. I'm sure there's a better way.
feel free to step in any time ;-)
<cfif #HTTP_REFERER# DOES NOT CONTAIN "127.0.0.1" and #HTTP_REFERER# DOES NOT CONTAIN "mysite.com">
<cfset application.OutsideLink = #HTTP_REFERER#>
</cfif>
I can see one problem with this...if in the referer link the mysite.com exists then it won't work. I'm sure there's a better way.
feel free to step in any time ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi gdemaria:,
I prefer your <cfif NOT isDefined("session.theRefe rrer")> method. thanks for the pointer.
Is there a difference between the cf http_referer and the cgi.http_referer?
I prefer your <cfif NOT isDefined("session.theRefe
Is there a difference between the cf http_referer and the cgi.http_referer?
not sure what you are referring to by "cf http_referer"
Coldfusion has a seriers of CGI scoped variables with system information such as the domain, the query string the IP address etc.
This one gives you the referrer...
CGI.HTTP_REFERER
In fact, all variables should be scoped to reduce bugs and improve performance. But that's another debate :)
Coldfusion has a seriers of CGI scoped variables with system information such as the domain, the query string the IP address etc.
This one gives you the referrer...
CGI.HTTP_REFERER
In fact, all variables should be scoped to reduce bugs and improve performance. But that's another debate :)
ASKER
>>not sure what you are referring to by "cf http_referer"
in coldfusion I don't need to add "cgi." as shown above there is no cgi and it "seems" to give the same result
eg <cfoutput>#HTTP_REFERER#</ cfoutput> <-- No mention of cgi here
is there a difference?
in coldfusion I don't need to add "cgi." as shown above there is no cgi and it "seems" to give the same result
eg <cfoutput>#HTTP_REFERER#</
is there a difference?
ASKER
the next part I need is to parse the OutsideLink. I've started it below...
<cfset OutsideLink = "http://www.google.com/search?hl=en&q=cars&aq=f&oq=">
<cfset outHTTP = Find("http://", OutsideLink)>
<cfset outHTTPS = Find("https://", OutsideLink)>
<cfset outWWW = Find("www", OutsideLink)>
<cfset OutsideDomain = ""> <!--- Should get domain whether 2 or 3 letters eg. .com or .ca --->
<cfset OutsideQuery = ""> <!--- Should get anything after domain - the "/" --->
<!--- Then do some sort of a replace to get OutsideDomain OutsideQuery --->
<cfoutput><p>
OutsideLink #OutsideLink#<br>
OutsideDomain #OutsideDomain#<br>
OutsideQuery #OutsideQuery#<br>
<br>
</p></cfoutput>
What is your objective with the parsing? You just want to get one part of it or are you trying to record every part of it... ? (what end result are you after...)
> in coldfusion I don't need to add "cgi." as shown above there is no cgi and it "seems" to give the same result
> eg <cfoutput>#HTTP_REFERER#</ cfoutput> <-- No mention of cgi here
> is there a difference?
There is no difference. Variables can be accessed without their scope..
#lastName#
#form.lastname#
#theQuery.lastName#
#variables.lastName#
But the right way to refer to variables is with the scope, in all cases...
> eg <cfoutput>#HTTP_REFERER#</
> is there a difference?
There is no difference. Variables can be accessed without their scope..
#lastName#
#form.lastname#
#theQuery.lastName#
#variables.lastName#
But the right way to refer to variables is with the scope, in all cases...
ASKER
when someone submits a form once we have the outside link we want to save the site in one field and the qury in the other field so we can internally build stats on where (the domain) and how (did they come form a specific page, what were the key words in the query, etc.)
so with the eg
http://www.google.com/search?hl=en&q=cars&aq=f&oq=
I want
OutsideDomain = google.com
OutsideQuery = search?hl=en&q=cars&aq=f&o q=
so with the eg
http://www.google.com/search?hl=en&q=cars&aq=f&oq=
I want
OutsideDomain = google.com
OutsideQuery = search?hl=en&q=cars&aq=f&o
ASKER
>But the right way to refer to variables is with the scope, in all cases...
ok, thanks for the pointer. I'm pretty much self taught in cf so it's nice to know how I "should" be doing things
ok, thanks for the pointer. I'm pretty much self taught in cf so it's nice to know how I "should" be doing things
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this is ok if we are sure to have a ? in the link but often there isn't one. I like the list functions though. :-) they should do the trick
> in the link but often there isn't one
If there isn't a ? then the code goes to the <cfelse> which handles no query string..
If there isn't a ? then the code goes to the <cfelse> which handles no query string..
ASKER
in your example the results are
outDomain www.google.com
outQuery hl=en&q=cars&aq=f&oq=
whereas I am looking for
OutsideDomain = google.com
OutsideQuery = search?hl=en&q=cars&aq=f&o q=
I suppose we could get rid of the www. with a replace
it's the second one that soncerns me...I need the search?
outDomain www.google.com
outQuery hl=en&q=cars&aq=f&oq=
whereas I am looking for
OutsideDomain = google.com
OutsideQuery = search?hl=en&q=cars&aq=f&o
I suppose we could get rid of the www. with a replace
it's the second one that soncerns me...I need the search?
it's easy enough to remove the first subdomain if you wish
<cfif listLen(outDomain,".") gt 2>
<cfset outDomain = listRest(outDomain,".")>
</cfif>
Are you sure you want the /search to be on the other side, it's not part of the query string, not sure what that would tell you?
<cfif listLen(outDomain,".") gt 2>
<cfset outDomain = listRest(outDomain,".")>
</cfif>
Are you sure you want the /search to be on the other side, it's not part of the query string, not sure what that would tell you?
> I suppose we could get rid of the www. with a replace
it's not always going to be www.
It could be anything really, including not there secure.theSite.com search.theSite.com etc..
It could even be ... secure.newyork.usa.mySite. com
it's not always going to be www.
It could be anything really, including not there secure.theSite.com search.theSite.com etc..
It could even be ... secure.newyork.usa.mySite.
ASKER
ok, I'm fine with OutsideDomain...see below.
It's OutsideQuery I'm still working on. I need the /search on the Query rather than the domain as you did above.
It's OutsideQuery I'm still working on. I need the /search on the Query rather than the domain as you did above.
<cfset theReferrer = "http://www.google.com/search/hl=en&q=cars&aq=f&oq=">
<cfif theReferrer contains "www.">
<cfset outDomain = Replace(listGetAt(theReferrer,2,"/"), "www.", "")>
<cfelse>
<cfset outDomain = listGetAt(theReferrer,2,"/")>
</cfif>
ASKER
>>It could be anything really, including not there secure.theSite.com search.theSite.com etc..
that's ok. I'm fine with that. the examples you gave are different to me. www doesn't give any more ingormation. If it was " secure.theSite.com " however we would know it came from the secure subdomain. Possibly useful.
that's ok. I'm fine with that. the examples you gave are different to me. www doesn't give any more ingormation. If it was " secure.theSite.com " however we would know it came from the secure subdomain. Possibly useful.
can should test for https:// to be secure, just as you did in your original example
The name "secure" does not ensure SSL...
The name "secure" does not ensure SSL...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Perhaps something like this to get the part after the domain...
<cfset outQuery = listRest(theReferrer,"/")>
<cfset outQuery = listRest(outQuery,"/")>
ASKER
I think I have it now. what do you think?
<cfset theReferrer = "https://google.com/search/hl=en&q=cars&aq=f&oq=">
<cfset outDomain = listGetAt(theReferrer,2,"/")>
<cfif left(outDomain,4) is "www.">
<cfset outDomain = listRest(outDomain,".")>
</cfif>
<cfset outQuery = listRest(theReferrer,"/")>
<cfset outQuery = listRest(outQuery,"/")>
<cfoutput>
outDomain: #outDomain#<br>
outQuery: #outQuery#<br>
</cfoutput>
ASKER
ListGetAt update with empty string throws error...seems to be common. looking into it
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ha, I had left me screen so I didn't see your post
ASKER
all works great now. Thanks for your help. :-)
Shawn
Shawn
ASKER
final code in application.cfm
thanks again.
thanks again.
<cfif NOT isDefined("application.OutsideLink")>
<cfset application.OutsideLink = cgi.HTTP_REFERER>
</cfif>
<cfif listLen(application.OutsideLink,"/") gt 1>
<cfset application.OutsideDomain = listGetAt(application.OutsideLink,2,"/")>
<cfif left(application.OutsideDomain,4) is "www.">
<cfset application.OutsideDomain = listRest(application.OutsideDomain,".")>
</cfif>
<cfset application.OutsideQuery = listRest(application.OutsideLink,"/")>
<cfset application.OutsideQuery = listRest(application.OutsideQuery,"/")>
<cfelse>
<cfset application.OutsideDomain = "">
<cfset application.OutsideQuery = "">
</cfif>
ASKER
<cfoutput>#HTTP_REFERER#</