Link to home
Create AccountLog in
Avatar of keevin
keevin

asked on

page referer

Hi
Is there any equivalent of Request.ServerVariables("URL") in coldfusion i'm trying HTTP_REFERER though it gave me the whole path. I need the page name only

Regards
Avatar of mkishline
mkishline

It sounds like you're looking for SCRIPT_NAME, but if that's not right either, you can do a <cfdump var="#CGI#" /> and get all the variable information.
Avatar of keevin

ASKER

script_name gives me /foldername/filename.cfm.

I'm looking for the file name only
Try ListLast(SCRIPT_NAME,'/')
Avatar of keevin

ASKER

actually the full path is like below which i've obtain using http_referer

http://www.abc.com/foldername/filename.cfm.

l need to get foldername/filename.cfm

SCRIPT_NAME should return foldername/filename.cfm
Avatar of keevin

ASKER

yeah, but i'm using frame in the page

so SCRIPT_NAME return foldername/topframe.cfm

i need to get foldername/mainframe.cfm
Avatar of keevin

ASKER

which i can get using http_referer or path_translator
Avatar of keevin

ASKER

i'm trying to use  ListSetAt(1,http_referer,'/') but been unsucessfull
ASKER CERTIFIED SOLUTION
Avatar of mkishline
mkishline

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
<cfset variables.referpath = CGI.HTTP_REFERER />
<cfset variables.path = ListLast(variables.referpath,"/") />
<cfset variables.referpath = Left(variables.referpath,Len(variables.referpath)-Len(variables.path)) />
<cfset variables.path = ListLast(referpath,'/')&"/"&path />

I will get you all to start using variable scopes correctly and stop overusing #'s in CFSETs ;oD

Another solution to this would be to treat cgi.script_name as a "/" delimited list as mkishline has done and delete the first two list items from cgi.script_name.

<!--- Remove the domain name --->
<cfset variables.refererPath = ListDeleteAt(cgi.script_name,2,"/")>
<!--- Remove the http:// --->
<cfset variables.refererPath = ListDeleteAt(variables.refererPath,1,"/")>

From "http://www.abc.com/foldername/filename.cfm" this will give you "foldername/filename.cfm"

If you're wondering why deleting the list element at position 2 removes the domain name when its actually in position 3 in the list, this is because CF ignores empty list elements.  The // between http: and www.abc.com consitutes an empty list item and is ignored.