Copy link to clipboard
Copied
Hi Everyone -
My application is built using ColdFusion MX7. In my application, I have a CFC with a function that is supposed to return the CGI.HTTP_REFERER.
When I call this method, it does not return anything.
<cffunction name="DumpReferrer" output="false" access="remote" returntype="string">
<cfset var referrer = CGI.HTTP_REFERER>
<cfreturn referrer>
</cffunction>
A call to this function from within a cfm page is not returning the referrer. How can I get at the referrer from within a CFC?
Thanks!
Copy link to clipboard
Copied
KenJohnson wrote:
A call to this function from within a cfm page is not returning the referrer. How can I get at the referrer from within a CFC?
Thanks!
Depends on how you are calling this CFC. CGI variables come from the web server (IIS, Apache, etc) and if the web server is not involved in the request then the CGI scope will not exist. If you are calling it locally with something like createObject("component"...) or similar, then the CGI should be there and your code should have worked.
If you are calling it externally with something like createObjec("webservice"...) which the access="remote" parameter suggests, then CGI will not exist and your code will not work.
You would need to pass the value into the function. Which is considered a best practice anyway. In OOD it is considered bad to have an object reference data that exists outside of itself. All data should exist inside the component or be passed into it as arguments. I admit this would make your function example fairly nonsensical since it will then only return the same value that was passed to it, but I am not sure if this is all the function is intended to do or just a simple example.
Copy link to clipboard
Copied
Thanks for your input Ian.
What I am actually trying to do is correctly set the value of the HTTP Referrer header variable within a cfhttp tag using the following parameter:
<cfhttpparam name="referer" type="cgi" value="#CGI.HTTP_REFERER#">
The cfhttp tag is contained within a cfc that is being invoked from a flex app using flash remoting.
I tried to hard code the value of the referrer tag similar to the following:
<cfhttpparam name="referer" type="cgi" value="http://myHardCodedUrl.com/fullPathTo/MyFile.cfm">
This didn't seem to work either.
I could obviously pass in the HTTP_REFERER into the flex app, and then pass it back in my remote call; however, I didn't think that would work since hardcoding the value of the parameter didn't appear to work.
Now that you know the details, do you have any suggestions about how I can go about this?
Copy link to clipboard
Copied
Not much advice other then that actual name of the cgi varaible is 'http_referer" not just referer.
But I can easily imagine that this is a variable that the web server sets for itself from TCP/IP data and not something you can influence. I have never dug that deep.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more