Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to determine if CF is running on localhost?

Guest
Sep 16, 2008 Sep 16, 2008
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.
515
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 16, 2008 Sep 16, 2008
What about approaching it the other way - check for the servers IP address on the production server rather than checking for localhost in testing?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 16, 2008 Sep 16, 2008
Check out the cgi scope.

<cfdump var="#cgi#">

cgi.server OR cgi.host are probably what you are looking for.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 16, 2008 Sep 16, 2008
Thank you!
I used this code:

<cfif CGI.SERVER_NAME EQ "localhost">
<cfset myflag = true>
<cfelse>
<cfset myflag = false>
</cfif>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 16, 2008 Sep 16, 2008
LATEST
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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources