Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referer page condition check

Status
Not open for further replies.

toyt78

Technical User
Apr 5, 2005
125
0
0
US
Isnt there something where I can write a condition on a page dependent on where the user comes from?

I have a page that clicks onto a record page where I want to put in a condition on the record page that if the users comes from a certain page then he will not see certain link.

Is this correct and consistent way of doing this??

Code:
<CFIF cgi.http_referer EQ "[URL unfurl="true"]http://www.thisSite.com/index.cfm">[/URL] 
   Cant View this link.
<cfelse>
   <a href="thisLink.com">Show link if your NOT coming from [URL unfurl="true"]http://www.thisSite.com/index.cfm</a>[/URL]
</cfif>
 
If the calling page is on your own site then it would be better to pass a variable through and check for that. The reason for this is that the referral string is set by the browser so it can't really be trusted. A lot of people totally block the referred from being passed or change it to something else.

At least using a variable you do not need to rely on the browser passing the referrer string.

Hope this helps

Wullie

Fresh Look - Quality Coldfusion/Windows Hosting

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
yeah the referrer can be a pain in the tush sometimes.

what I would do is add a line in your Application.cfm file

<session.lastPage = cgi.path_info>

then use a similar cfif like you have above.

Code:
<CFIF session.lastPage EQ "/index.cfm"> 
   Cant View this link.
<cfelse>
   <a href="thisLink.com">Show link if your NOT coming from /index.cfm</a>
</cfif>

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
what I would do is add a line in your Application.cfm file

<session.lastPage = cgi.path_info>

Since Application.cfm gets executed first, wouldn't the cgi.path_info resets to the current page? Maybe something like this in Application.cfm?
Code:
<cfif isDefined('session.currPage')>
	<cfset session.prevPage = session.currPage>
<cfelse>
	<cfset session.prevPage = "">
</cfif>
<cfset session.currPage = cgi.path_info>

Speaking of cgi.path_info, it returns me blank in my PC developer version of cold fusion. I ended up using cgi.script_name. Is there any reason why cgi.script_name doesn't work as well?

Regards,
Min
 
Since Application.cfm gets executed first, wouldn't the cgi.path_info resets to the current page? Maybe something like this in Application.cfm?"

Nope. only coldfusion knows about that. The web server and browser have no idea... all the includes, cfcs, custom tags, etc... they are all run from a single http request.

when you ask for index.cfm, your browser is asking the http web server for index.cfm. Your web server knows that that belongs to coldfusion, so it tells coldfusion that it needs index.cfm. cold fusion does everything it needs to to prepare index.cfm, including running application.cfm, included files, and all your scripting, and hands only the resulting html back to the web server as index.cfm. the web server gives it back to the browser and your done.

 
imstillatwork,
minli98 is correct in that thinking. my logic is a little off, but so is min's. CF gets path info and script name from the server. only referrer comes from the browser.

<cfparam name = "session.lastPage" default = "">
<cfparam name = "session.thisPage" default = "">

<cfif session.thisPage neq "">
<cfset session.lastPage = session.thisPage>
<cfset session.thisPage = cgi.Script_name>
<cfelse>
<cfset session.thisPage = cgi.Script_name>
</cfif>

that will keep lastPage one page behind of thisPage.



We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top