I'm going through a coldfusion code and encountered following information. I didn't understand some part of it. My questions are as follows:
CODE:
<cfif FINDNOCASE( "xyz.seta", "#CGI.SERVER_NAME#") GT 0 > <cfset PublicPath = "abcxyz/NEW_abc/Public"> <cfset SessionPath = "abcxyz/NEW_abc/Session">I understand that FINDNOCASE is used to find the first occurance of a substring in a string, from a specified start position.
Function Syntax: FindNoCase(substring, string [, start ])1) So, in my case, xyz.seta substring is searched starting from " #CGI.SERVER_NAME# " ? Am I confused here?
2) Question Regarding the PublicPath and SessionPath defined:
When I checked the server (after logging into it using VNC Viewer), only folders that are visible to me are Public and Session. Where can I find the path before it? Please clarify or let me know if I need to study something more before asking such question.
Thanks
34 Answers
You are correct about your first assumption. The FINDNOCASE will return the index of the start of the sub-string. I think that CF indexes are one based (not 0 based). Thus if the string "xyz.seta" exists in the variable #CGI.SERVERNAME#, the value returned will always be greater than zero and the contents of the CFIF block will execute.
On the variables PublicPath and SessionPath. These variables are page variables as they are not defined by any other scope designation (e.g. session or application). They only exist when this page is processing. If this is in your Application.cfm, it will execute every time this Application.cfm file is called. The values of the variables are being set to paths relative to the the current directory. If you want them absolute, add a slash to the front of the string literals (e.g. "/abcxyz/NEW_abc/Public"). That will make them absolute paths from the document directory of the web server. The web server path varies from OS to OS.
I have no idea what your second question is even asking, let alone the answer, but I can answer the first one.
You are misreading the (fairly clear, I thought) docs for findNoCase().
Function Syntax: FindNoCase(substring, string [, start ])
Code:FINDNOCASE( "xyz.seta", "#CGI.SERVER_NAME#")
So xyz.seta is the substring, and CGI.SERVER_NAME is the string. And the optional start attribute is not specified, so is implied to be 1, ie: the beginning of the string.
So the code is looking for xyz.seta within the value of CGI.SERVER_NAME (and will return the position at which it is found, or zero if not found.
This is a pretty simple configuration statement.
If the address that is being accessed (CGI.server_name) at least contains the domain xyx.seta then set these two variables, PublicPath and SessionPath, to be these two values.
I imagine that there is an else that says set the paths to be two different values.
If you look on the server where xyz.seta is hosted you should find those physical file paths.
That's it really. Nothing more nothing less.
You might want to use cfdump and cfabort to umm... dump out the content of CGI scope and variables scope to see what is in there and what is being set. Use cfabort to stop processing immediately after the cfdump.
That should help you to understand what variables are there available to you and what the code above is doing.
0FindNoCase(substring, string [, start ])is the syntax where the "start" is an optional parameter which is not passed here. The substring "xyz.seta" is searched into the "CGI.SCRIPTNAME". The findnocase function returns 0 if no matches found or a positive number if found(The returned value is the starting index of the substring into the string and the index starts from 1 and not 0). So the statement can be as
<cfif FINDNOCASE( "xyz.seta", "#CGI.SERVER_NAME#")>as the return value will be positive if matches are found