Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / July 2008



Tip: Looking for answers? Try searching our database.

are application variables 'user specific'?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
happysailingdude - 03 Jul 2008 13:49 GMT
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?
Daverms - 03 Jul 2008 13:51 GMT
Hi,

Thats where <cflock> comes into play surround your application variable setting with <cflock> and set your attributes as required.
happysailingdude - 03 Jul 2008 14:03 GMT
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?
Ian Skinner - 03 Jul 2008 14:28 GMT
>  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.
Dan Bracuk - 03 Jul 2008 14:33 GMT
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.
happysailingdude - 03 Jul 2008 16:47 GMT
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
Ian Skinner - 03 Jul 2008 17:51 GMT
> thanks guys, i've chaned now to:
>
[quoted text clipped - 9 lines]
>
>  <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.
larryclyons - 04 Jul 2008 13:56 GMT
On Jul 3, 11:47 am, "happysailingdude" <webforumsu...@macromedia.com>
wrote:
> thanks guys, i've chaned now to:
>
[quoted text clipped - 20 lines]
>
>  cheers

A couple of things. As for the bots issue, simply do a bit of
http_agent sniffing then create different cf applications for either

For instance:
<cfif isBot()>
    <cfapplication name="appName"
        clientmanagement="No"
        sessionmanagement="yes"
        setclientcookies="yes"
        setDomainCookies = "no"
        sessiontimeout="#createTimeSpan(0,0,0,30)#"
        applicationtimeout="#createTimeSpan(1,0,0,0)#"
        clientstorage="cookie">
<cfelse>
    <cfapplication name="appName"
        clientmanagement="No"
        sessionmanagement="Yes"
        setclientcookies="Yes"
        sessiontimeout="#createTimeSpan(0,2,0,0)#"
        applicationtimeout="#createTimeSpan(1,0,0,0)#"
        clientstorage = "cookie"
        setDomainCookies = "yes">
</cfif>

the isBot() function uses a bit of Regex to sniff out whether the
http_User_agent is a bot:

<cffunction name="isBot" output="false" access="public"
displayname="isBot" hint="I check for bots and return a boolian 1 for
bot"   returntype="boolean">
    <!--- adapted from http://www.bennadel.com/blog/39-Turning-Off-Session-Management-for-Web-Spiders.htm
--->
    <cfset var strTempUserAgent = LCase( CGI.http_user_agent )>
    <cfif (NOT Len(strTempUserAgent)) OR
            REFind( "bot\b", strTempUserAgent ) OR
            REFind( "\brss", strTempUserAgent ) OR
            Find("google",strTempUserAgent ) or
            Find("yahoo",strTempUserAgent ) or
            Find("msn",strTempUserAgent ) or
            find("aol",strTempUserAgent ) or
            find("baidu", strTempUserAgent) >
        <cfreturn true>
    <cfelse>
        <cfreturn false>
    </cfif>
</cffunction>

So basically you give the bot a separate application.cfm with a short
session timeout.

As for the "odd scope" of customer content. Its actually an unscoped
variable that ends up being within the variables scope, that dies with
each page request. Essentially when you call customcontent.message,
you actually are calling variables.customcontent.message.

regards,
larry
happysailingdude - 04 Jul 2008 16:19 GMT
thanks guys, i really appreciate all of your help :)

thanks again.

kind regards

Nick
BKBK - 05 Jul 2008 11:13 GMT
[b]Topic Title:[/b] [i]are application variables 'user specific'?[/i]
No, application variables apply to every user. User-specific scopes are
session, client and cookie.

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

[i]> ... 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?)[/i]
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 band width. You could use a robots.txt
file to prevent bots from crawling pages with 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.