8 Replies Latest reply on Jul 5, 2008 3:13 AM by BKBK

    are application variables 'user specific'?

    happysailingdude Level 1
      hi - i've got a feeling i may have done something stupid.

      we have several domains all pointing to one application.

      in application we look at the cgi.http_host to work out which site the domain the user is expecting and then serve up customised content accordingly.

      only this is i've set put the customised content in application scoped vars - is that a bad move?

      eg. in application.cfm i have:

      <cfif cgi.http_host eq 'www.redredred.com' >
      <cfset application.message= "welcome - we love the colour red" >
      <cfelseif cgi.http_host eq 'www.blueblueblue.com' >
      <cfset application.message= "welcome - to our site where we love blue" >
      <cfelse>
      <cfset application.message= "welcome to our site (we love all colours)" >
      </cfif>

      then in the index.cfm:

      <cfoutput>#application.message#</cfouput>

      is there a chance that by doing this someone who has visited www.redredred.com will get a message about blue?
        • 1. are application variables 'user specific'?
          Daverms Level 3
          Hi,

          Thats where <cflock> comes into play!. Surround your application variable setting with <cflock> and set your attributes as required.

          • 2. Re: are application variables 'user specific'?
            happysailingdude Level 1
            thanks Daverms - I'm just wondering if i should just set 'ordinary' variables instead to make it simple, like this..

            in application.cfm i have:

            <cfif cgi.http_host eq 'www.redredred.com' >
            <cfset temp.message= "welcome - we love the colour red" >
            <cfelseif cgi.http_host eq 'www.blueblueblue.com' >
            <cfset temp.message= "welcome - to our site where we love blue" >
            <cfelse>
            <cfset temp.message= "welcome to our site (we love all colours)" >
            </cfif>

            then in the index.cfm:

            <cfoutput>#temp.message#</cfouput>

            what do you think?
            • 3. Re: are application variables 'user specific'?
              Level 7
              happysailingdude wrote:
              >
              > is there a chance that by doing this someone who has visited www.redredred.com
              > will get a message about blue?
              >

              Not only a chance, but there is something wrong if the person does not
              get this message, once the next user has set the variable to blue.

              Application variables are global to the application and will be shared
              by all users of that application. That is the designed and desired
              purpose of application variables.

              In ColdFusion an application is defined by any template that shares the
              same 'name' as defined in either the name parameter of a
              <cfapplication...> tag or the this.name property of an Application.cfc file.

              If all these web sites are using the same string for the application
              name then they share the same application scope and they will all have
              the same value for application.message. And this value will be the
              value set by the last visitor to any of the sites.

              <cflock...> is not relevant to this issue. It will prevent the variable
              from being set at the exact same moment by multiple users on multiple
              sites, but it will not stop the value from changing sequentially as
              first one, then another user visits any of these sites and changing the
              value.

              The solution to your problem is to set different application scopes by
              dynamically setting the application name. Thus each website will be
              separate and distinct applications with their own application scope
              variables and your system should behave the way desired.



              • 4. Re: are application variables 'user specific'?
                Dan Bracuk Level 5
                If you are going to use the message more than once, make it a session variable. Then you can set it just once and not on every page request.

                I also think that you should use an application.cfc instead of an application.cfc. Then you can set that variable in the onSessionStart function.
                • 5. Re: are application variables 'user specific'?
                  happysailingdude Level 1
                  thanks guys, i've chaned now to:

                  <cfif cgi.http_host eq 'www.redredred.com' >
                  <cfset customcontent.message= "welcome - we love the colour red" >
                  <cfelseif cgi.http_host eq 'www.blueblueblue.com' >
                  <cfset customcontent.message= "welcome - to our site where we love blue" >
                  <cfelse>
                  <cfset customcontent.message= "welcome to our site (we love all colours)" >
                  </cfif>

                  and

                  <cfoutput>#customcontent.message#</cfouput>

                  i haven't gone for the session var option as i'm not using session vars (at this time) and i've been told to give them a wide berth due to search bots creating a new session on each page they visit when they crawl the site and apparantly as CF tries to keep track of the resulting numerous session vars in memory - apparantly this can result in a loss of performance (any comments on that?)

                  also is my 'odd' scope of "customecontent" ok?

                  cheers
                  • 6. Re: are application variables 'user specific'?
                    Level 7
                    happysailingdude wrote:
                    > thanks guys, i've chaned now to:
                    >
                    > <cfif cgi.http_host eq 'www.redredred.com' >
                    > <cfset customcontent.message= "welcome - we love the colour red" >
                    > <cfelseif cgi.http_host eq 'www.blueblueblue.com' >
                    > <cfset customcontent.message= "welcome - to our site where we love blue" >
                    > <cfelse>
                    > <cfset customcontent.message= "welcome to our site (we love all colours)" >
                    > </cfif>
                    >
                    > and
                    >
                    > <cfoutput>#customcontent.message#</cfouput>

                    This logic will have to be run each and every request, since you are not
                    persisting the data in any way.

                    >
                    > i haven't gone for the session var option as i'm not using session vars (at
                    > this time) and i've been told to give them a wide berth due to search bots
                    > creating a new session on each page they visit when they crawl the site and
                    > apparantly as CF tries to keep track of the resulting numerous session vars in
                    > memory - apparantly this can result in a loss of performance (any comments on
                    > that?)

                    It true that CF will create a session scope for every request that does
                    not have one created and that it will keep this scope for the time it
                    has been configured to do so.

                    But this is not a reason to avoid using it. Just to use it
                    intelligently and to not fill it with a bunch of unnecessary data just
                    because it is easy.
                    • 7. Re: are application variables 'user specific'?
                      happysailingdude Level 1
                      thanks guys, i really appreciate all of your help :)

                      thanks again.

                      kind regards

                      Nick
                      • 8. are application variables 'user specific'?
                        BKBK Adobe Community Professional & MVP
                        Topic Title: are application variables 'user specific'?
                        No, application variables apply to every user. User-specific scopes are session, client and cookie.

                        Topic Summary: ie if i set an application var in cfapplication for one user wil other users have access to that var too?
                        Yes, for the same reason.

                        > ... search bots creating a new session on each page
                        > they visit when they crawl the site and apparantly
                        > as CF tries to keep track of the resulting numerous
                        > session vars in memory - apparantly this can
                        > result in a loss of performance (any comments on
                        > that?)

                        It is true. Using session IDs is one of the factors that can make search-bots to overstay their welcome at your site. They may create infinite loops around the session URLs and consume too much bandwidth. You could use a robots.txt file to prevent bots from crawling pages that have session IDs.

                        That may be impossible, or it may be important that all the pages of your site be indexed. Then use cookies instead. That is, for example, Googlebot's advice.