Skip to main content
September 16, 2008
Question

How to determine if CF is running on localhost?

  • September 16, 2008
  • 4 replies
  • 567 views
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.
    This topic has been closed for replies.

    4 replies

    Inspiring
    September 17, 2008
    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/
    September 16, 2008
    Thank you!
    I used this code:

    <cfif CGI.SERVER_NAME EQ "localhost">
    <cfset myflag = true>
    <cfelse>
    <cfset myflag = false>
    </cfif>
    Inspiring
    September 16, 2008
    Check out the cgi scope.

    <cfdump var="#cgi#">

    cgi.server OR cgi.host are probably what you are looking for.
    Known Participant
    September 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?