0
How to determine if CF is running on localhost?

/t5/coldfusion-discussions/how-to-determine-if-cf-is-running-on-localhost/td-p/149709
Sep 16, 2008
Sep 16, 2008
Copy link to clipboard
Copied
Sorry if this is a dumb question.
I'm trying to run different code when I test my website locally versus run it on the production server. Specifically, the production server puts full URLs into the web pages (www.fubar.com/page1.cfm) versus my testing server which I like to run as a relative URL (../page1.cfm).
I do the full URLs on the production server to have complete control over the secure/nonsecure elements, but I don't have a secure cert on localhost so I need all the elements to be non-SSL.
Right now I just have a boolean flag in application.cfc I manually change so the code knows where it is being run, but sometimes I forget to change it when I sync. Is there a function that I can use to set the flag for me? I found IsLocalHost() but I would need to pass it an IP.
Thank you for any help you might be able to offer.
I'm trying to run different code when I test my website locally versus run it on the production server. Specifically, the production server puts full URLs into the web pages (www.fubar.com/page1.cfm) versus my testing server which I like to run as a relative URL (../page1.cfm).
I do the full URLs on the production server to have complete control over the secure/nonsecure elements, but I don't have a secure cert on localhost so I need all the elements to be non-SSL.
Right now I just have a boolean flag in application.cfc I manually change so the code knows where it is being run, but sometimes I forget to change it when I sync. Is there a function that I can use to set the flag for me? I found IsLocalHost() but I would need to pass it an IP.
Thank you for any help you might be able to offer.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explorer
,
/t5/coldfusion-discussions/how-to-determine-if-cf-is-running-on-localhost/m-p/149710#M13697
Sep 16, 2008
Sep 16, 2008
Copy link to clipboard
Copied
What about approaching it the other way - check for the
servers IP address on the production server rather than checking
for localhost in testing?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/how-to-determine-if-cf-is-running-on-localhost/m-p/149711#M13698
Sep 16, 2008
Sep 16, 2008
Copy link to clipboard
Copied
Check out the cgi scope.
<cfdump var="#cgi#">
cgi.server OR cgi.host are probably what you are looking for.
<cfdump var="#cgi#">
cgi.server OR cgi.host are probably what you are looking for.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/coldfusion-discussions/how-to-determine-if-cf-is-running-on-localhost/m-p/149712#M13699
Sep 16, 2008
Sep 16, 2008
Copy link to clipboard
Copied
Thank you!
I used this code:
<cfif CGI.SERVER_NAME EQ "localhost">
<cfset myflag = true>
<cfelse>
<cfset myflag = false>
</cfif>
I used this code:
<cfif CGI.SERVER_NAME EQ "localhost">
<cfset myflag = true>
<cfelse>
<cfset myflag = false>
</cfif>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/how-to-determine-if-cf-is-running-on-localhost/m-p/149713#M13700
Sep 16, 2008
Sep 16, 2008
Copy link to clipboard
Copied
iirc, cgi.http_host is a more commonly available cgi variabe
between
various web servers. use that instead of cgi.server_name.
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
various web servers. use that instead of cgi.server_name.
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

