willa666
asked on
redirect a user by where they came from
I have a cold fusion app that i need to add some redirection code to trhe front page of
the home page is index.cfm
when this page is accessed i want to find out where the user has come from, if the user has come from URL a then i dont want the script to anything, it should just carry on with the rest of the code on the page. but if the refurer is not URL a then the user should be redirected to URL B
URL_A = http://mysite.com/application
URL_B = http://somothersite/application
the home page is index.cfm
when this page is accessed i want to find out where the user has come from, if the user has come from URL a then i dont want the script to anything, it should just carry on with the rest of the code on the page. but if the refurer is not URL a then the user should be redirected to URL B
URL_A = http://mysite.com/application
URL_B = http://somothersite/application
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good morning _agx_
So what would you suggest?
So what would you suggest?
Good day :)
I would still use CGI.http_referer. Its a simple string variable that you can parse using string or list functions. I only mentioned it because some people don't realize the value can be blank. So they fail to setup a condition to handle that case.
If you create a simple page with a link, you can experiment with the available CGI variables.
<!--- code: myindexpage.cfm --->
<a href="somedirec/somepage.c fm?id=23&p hrase=maps ">GO</a>
<!--- code for: somedirec/somepage.cfm --->
<!--- shows all CGI variables --->
<cfdump var="#CGI#">
Results from: somedirec/somepage.cfm
========================== =========
HTTP_REFERER = http://127.0.0.1/somedirec/somePage.cfm?id=85&phrase=maps
I would still use CGI.http_referer. Its a simple string variable that you can parse using string or list functions. I only mentioned it because some people don't realize the value can be blank. So they fail to setup a condition to handle that case.
If you create a simple page with a link, you can experiment with the available CGI variables.
<!--- code: myindexpage.cfm --->
<a href="somedirec/somepage.c
<!--- code for: somedirec/somepage.cfm --->
<!--- shows all CGI variables --->
<cfdump var="#CGI#">
Results from: somedirec/somepage.cfm
==========================
HTTP_REFERER = http://127.0.0.1/somedirec/somePage.cfm?id=85&phrase=maps
Oops. The referrer results should have been:
HTTP_REFERER = http://127.0.0.1/somedirec/somePage.cfm?id=23&phrase=maps
HTTP_REFERER = http://127.0.0.1/somedirec/somePage.cfm?id=23&phrase=maps
ASKER
so would something like this work, for what i want to do?
<cfset URLA ="http://mysite.com/application">
<cfset URLB ="http://somothersite/application">
<cfif #CGI.HTTP_REFERER# eq URLA >
<cflocation url=URLB >
<cfelse>
</cfif>
<cfset URLA ="http://mysite.com/application">
<cfset URLB ="http://somothersite/application">
<cfif #CGI.HTTP_REFERER# eq URLA >
<cflocation url=URLB >
<cfelse>
</cfif>
The referer may also contain url variables:
http://mysite.com/application/index.cfm?id=23&phrase=maps
So it might be safer to use something like findNoCase() rather than EQ
<cfif findNoCase("http://mysite.com/application", CGI.HTTP_REFERER) gt 0>
... do something
<cfelse>
... do something else
</cfif>
http://mysite.com/application/index.cfm?id=23&phrase=maps
So it might be safer to use something like findNoCase() rather than EQ
<cfif findNoCase("http://mysite.com/application", CGI.HTTP_REFERER) gt 0>
... do something
<cfelse>
... do something else
</cfif>
ASKER
Ok, so does findNoCase look for a matching string inside CGI.HTTP_REFERER?
IE if the CGI.HTTP_REFERER was http://mysite.com/application/somepage.cfm?var1=val1 then it would find http://mysite.com/application in that string? and of course all the letter are converted to lower case.
IE if the CGI.HTTP_REFERER was http://mysite.com/application/somepage.cfm?var1=val1 then it would find http://mysite.com/application in that string? and of course all the letter are converted to lower case.
<!--- Param URL variables. --->
<cfparam
name="URL.A"
type="string"
default="No"
/>
<cfparam
name="URL.B"
type="boolean"
default="false"
/>
<!---
Check to see if URLA call has been requested.
If so, we are just going to Locate back to self.
This will allow us to see what the referrer is seen
as by the target page.
--->
<cfif URL.A>
<cflocation
url="#CGI.script_name#?URL A=Yes"
addtoken="false"
/>
</cfif>
</cfsilent>
<cfoutput>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
</head>
<body>
<p>
CFLocation: #URL.A#<br />
Referrer: #ListFirst(
ListLast( CGI.http_referer, "\/" ),
"?"
)#
</p>
<p>
<a
href="#CGI.script_name#"
>Refresh</a>
|
<a
href="#CGI.script_name#?UR L.B=true"
>Refresh With CFLocation</a>
</p>
</body>
</html>
</cfoutput>
Try this shd take care of blank scenario also as mentioned by agx...
let me know if it works......
<cfparam
name="URL.A"
type="string"
default="No"
/>
<cfparam
name="URL.B"
type="boolean"
default="false"
/>
<!---
Check to see if URLA call has been requested.
If so, we are just going to Locate back to self.
This will allow us to see what the referrer is seen
as by the target page.
--->
<cfif URL.A>
<cflocation
url="#CGI.script_name#?URL
addtoken="false"
/>
</cfif>
</cfsilent>
<cfoutput>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
</head>
<body>
<p>
CFLocation: #URL.A#<br />
Referrer: #ListFirst(
ListLast( CGI.http_referer, "\/" ),
"?"
)#
</p>
<p>
<a
href="#CGI.script_name#"
>Refresh</a>
|
<a
href="#CGI.script_name#?UR
>Refresh With CFLocation</a>
</p>
</body>
</html>
</cfoutput>
Try this shd take care of blank scenario also as mentioned by agx...
let me know if it works......
> Ok, so does findNoCase look for a matching string inside CGI.HTTP_REFERER?
Yes
Yes
ASKER
thanx sandy12879 i will try this and my little hack code and see how we go.
I have to drive into the office now so it will be an hour or so till this gets tested :)
I have to drive into the office now so it will be an hour or so till this gets tested :)
ASKER
Hi guys
well #CGI.HTTP_REFERER# does not show up the referer if you go from one domain to another.
Any ideas?
W
well #CGI.HTTP_REFERER# does not show up the referer if you go from one domain to another.
Any ideas?
W
Why do you say that?
ASKER
ok so i managed to sort it out guys! :)
ASKER
could you provide a full example, i am not a CF developer and need this to add a hot fix to the app :)