Skip to main content
Inspiring
July 15, 2010
Question

Application.cfc and user accounts

  • July 15, 2010
  • 1 reply
  • 1023 views

Hi, I"m working with Coldfusion 9, and I've been learning about how to use it from Lynda Training DVDs and the book "Adobe Coldfusion 9 application construction kit."

The Dynamic Development with Dreamweaver CS4 DVD says to do user login stuff with the Application.cfc file, but in the book, it says:

"This means you should not use application variables if you want a seperate copy of the variable to exist for each visitor to your site.  IN other words, application variables shouldn't be used for anything personalized, because they don't distinguish between yoiur site's visitors."

All I'm trying to do is let a user log in to my site, and when they go to discussion board, or post comments on an article and things like that, I want to have "You are logged in as: [username]" as opposed to a username text field they can enter their username on....so, when they click 'post comment' the username they are logged in as is submitted automatically along with the comment they post.

Any help would be greatly appreciated.

Thank you,

Mike

    This topic has been closed for replies.

    1 reply

    Inspiring
    July 15, 2010

    The books do not contradict each other.  Just because something is done in Application.cfc does not mean that the action is to set an application variable.

    Have you studied the various scopes of variables available to you yet?  Do you understand the difference between an application and session variable?

    wycksAuthor
    Inspiring
    July 15, 2010

    well I know that a session variable is something that stays with the user until they close their browser or times out, and from what I've learned so far (its probably obvious I'm a beginner) the Application.cfc does the same thing when the J2EE session is turned on in the coldfusion but with it turned off, when the user returns to the page, the information is saved--if i'm understanding correctly.

    I guess what I"m not understanding is when I read:

    "This means you should not use application variables if you want a seperate copy of the variable to exist for each visitor to your site.  IN other words, application variables shouldn't be used for anything personalized, because they don't distinguish between yoiur site's visitors."

    it makes it sound like if I'm using Application.cfc to log one user in, when that user goes to another page to post a comment or something, it will work fine, but then if another user logs in it overwrites the first user's login stuff and both will be logged in as the second user's username...

    the thing is, I understand how to use Application.cfc to authenticate a user, but I'm scared that if I do all that, everything will appear to be fine when I test everything on my localhost, but then when I put it online, the problem above will happen because that would be the first time I could try logging in several users at the same time.

    Inspiring
    July 15, 2010

    I suspect that you misunderstand the difference between code in an Application.cfc file and the application scope.  Just because code is part of the Application.cfc file doen't mean the variables with in are part of the application scope.

    You may wish to review the CF documentation on scope and post any follow up questions with code samples from your Application.cfc.

    About scopes:
    http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7fd5.html