bbuller
bbuller

Reputation: 195

Need help understanding Coldfusion URL Referral

I have a ColdFusion site on which I need to display different text based on how the user got to the page.

I.e.,

<cfif user comes from sitemap.cfm>
    Display this text
<cfelse>
    display this text
</cfif>

Can someone point me in the right direction?

Upvotes: 1

Views: 278

Answers (2)

user1199680
user1199680

Reputation: 176

Using CGI.HTTP_REFERER is one possible solution as mentioned by David Faber. It's the easiest way and I would recommend it.

If you don't, or can't, trust the CGI.HTTP_REFERER value for some reason, then another solution is to implement a kind of tracking of your user (more precisely of his http request). For example you could :

  • Use a (key,value) in the Session scope (and not Request scope) e.g By implementing it in an onRequestStart(String targetPage) inside your Application.cfm (or directly in sitemap.cfm ?). Then do what you need or want to do depending on the targetPage value and your SESSION[key]value.
  • Use the same technique but with the COOKIE scope (or with cfcookie ?). Depends on the http request workflow...

I think there may be other tracking techniques and it's up to you :-)

Upvotes: 1

David Faber
David Faber

Reputation: 12485

You want to look at the CGI environment variables, specifically HTTP_REFERER (and no, that isn't misspelled -- or, I should say, the name of the CGI variable is misspelled).

I believe the value of HTTP_REFERER will contain the entire URL, including the query string, so you'll have to parse it -- or perhaps use CONTAINS or findNoCase() in your <cfif> statement:

<cfif findNoCase("sitemap.cfm", cgi.HTTP_REFERER)>
    Display this text
<cfelse>
    display this text
</cfif>

It's important to note that the value of HTTP_REFERER will be empty if you're going from HTTP to HTTPS -- and vice-versa, I believe.

Upvotes: 6

Related Questions