Hard to explain, has to do with users, last logged intime, and my database

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Hard to explain, has to do with users, last logged intime, and my database

    Okay everyone this is closly related to my other topic but they are different.
    I keep a field in my database called loggedin, which is set to yes if they are
    logged in, and no if they are not. However as well all know it is rather
    difficult to say who really is or is not logged in because users usually close
    the web browser without logging out. So what i decided was to make a field
    that records the last time they logged in, then have my index page check to see
    if they logged in more than one half hour ago. If so, then log them out. I know
    ill be using the datediff function. I just can't seem to put it together in my
    brain, how do I write a query that updates users, that says if lastlogged was
    more than a half hour ago, set loggedin to no?

    kenji776 Guest

  2. Similar Questions and Discussions

    1. Flashcom Guru Please Explain if this makes sense.Multiple users at one ip address getting rejected?
      Hi, Today we had 17 students at a school, at a single ip address, attempt to connect to my flashcom server to listen to audio files. They had...
    2. MSI file installation fails on computers with logged-inrestricted users
      I'm trying to package Flash Player 8b for silent distribution via Microsoft SMS. My package works correctly on computers where a logged in user is...
    3. how to see users logged into mysql?
      hi! how to see users logged into mysql? I would like to know who is actually logge into MySQL under my slack greetings jerzu
    4. Displaying multiple values - Hard to explain here...
      Hi All! Ok. I've got a query that's pulling data from multiple child tables based on the primary key from the parent table and displaying it in...
    5. asp get Table Column ( Show Active Users Names Logged On )
      Hello; I know how to get a "Database Table" with ASP. But what I am trying to get is the Table Column. This is what I am needing. ( Could...
  3. #2

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    I don't know what db you are using, so I will use access for this example.

    Assuming "loggedin" is a YES/NO field, when the user logs in you set
    "loggedin" to YES and the "loggedInDate" to the current date and time. To log
    users out, just find all records where "loggedin" is YES and the "loggedInDate"
    is more than thirty minutes ago OR the "loggedInDate" is NULL (i.e. something
    is wrong if there is no login date).



    <!--- something like this ...--->
    <cfquery name="loginUser" datasource="#DSN#">
    UPDATE yourTable
    SET LoggedIn = YES,
    LoggedInDate = #CreateODBCDateTime(rightNow)#
    WHERE userID = #currentUserID#
    </cfquery>

    <cfset thirtyMinutesAgo = DateAdd("n", -30, now())>
    <cfquery name="logoutUsers" datasource="#DSN#">
    UPDATE yourTable
    SET LoggedIn = NO,
    LoggedInDate = NULL
    WHERE LoggedIn = YES AND (
    LoggedInDate < #CreateODBCDateTime(thirtyMinutesAgo)# OR
    LoggedInDate IS NULL
    )
    </cfquery>

    mxstu Guest

  4. #3

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    I am using MS access, I know its crappy and i should be using oracle, but
    whatever. I am not familiar with
    #CreateODBCDateTime(rightNow)#
    is that like the now() function? Thanks a bunch for the code, that helps quite
    a bit, I was having like a logical breakdown and I could not for the life of me
    figure out how to write that query. Thank again!

    kenji776 Guest

  5. #4

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    Yes, it's awful when your brain hits a temporary road block!

    Oops. I forgot to include the line where I set the variable named "rightNow".
    Yes, it's basically another way of saying SET ColumnName = #Now()# ... (i.e.
    the current CF date and time).

    mxstu Guest

  6. #5

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    Btw, you could really condense these two statements into one line. I split it
    out for clarity...

    <cfset thirtyMinutesAgo = DateAdd("n", -30, now())>
    ......
    LoggedInDate < #CreateODBCDateTime(thirtyMinutesAgo)# OR
    .......


    condensed:
    ..... LoggedInDate < CreateODBCDateTime(DateAdd("n", -30, now())) .....



    mxstu Guest

  7. #6

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    Alright cool thanks, so that code should work with MS access? Im just curious
    so I know if I should be expecting errors when I go to paste it in or not, I
    can' t test right now cause im at a friends house just checking these forums ;)

    kenji776 Guest

  8. #7

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    wow that is an ugly looking line of code
    LoggedInDate < CreateODBCDateTime(DateAdd("n", -30, now()))
    haha I don't even know what the hell that is! Funny to me for some reason.
    kenji776 Guest

  9. #8

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    It worked fine for me with Access 2000. Just make sure
    A) LoggedIn is type "YES/NO"
    B) LoggedInDate is type "date/time" AND
    C) You replace the line: #CreateODBCDateTime(rightNow)# with: #Now()#

    mxstu Guest

  10. #9

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    oh well those could be slight problems,
    yes/no is a string,
    and last_logged_in is a string also.
    Is there an easy way to make you query work with that? I would change the
    database, but some other things use the database and know those vars as strings.

    kenji776 Guest

  11. #10

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    Originally posted by: kenji776
    wow that is an ugly looking line of code
    LoggedInDate < CreateODBCDateTime(DateAdd("n", -30, now()))
    haha I don't even know what the hell that is! Funny to me for some reason.

    Don't knock it till you've tried it ;-) You should use the one that seems
    more clear, that way you won't have trouble with it 6 months down the road.

    In a nutshell ...

    1. Get the time now
    LoggedInDate < CreateODBCDateTime(DateAdd("n", -30, now()))

    2. Deduct thirty minutes from it
    LoggedInDate < CreateODBCDateTime(DateAdd("n", -30, now()))

    3. Now convert it into a date and time format Access can understand
    LoggedInDate < CreateODBCDateTime(DateAdd("n", -30, now()))

    ie. format {ts '2005-07-28 23:44:02'}

    4. Now find all users that logged in more than 30 minutes ago
    LoggedInDate < CreateODBCDateTime(DateAdd("n", -30, now()))




    mxstu Guest

  12. #11

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    Is there an easy way to make you query work with that?

    Changing the YES/NO field to a "text" is pretty simple. IMO using YES/NO is
    better but the change would not be difficult.

    I would recommend changing the logged in date to "date/time". Storing dates
    as strings is just asking for trouble.

    mxstu Guest

  13. #12

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    your probobly right, i guess il make the change and deal with the errors as they come from the other pages.
    kenji776 Guest

  14. #13

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    What else are you using the field for ... and how do you insert the date/time into that field? ex. using #Now()#?
    mxstu Guest

  15. #14

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    I guess I don't know for a fact if it will cause errors, its just that I havn't
    used types of fields very often, and im not really sure sometimes how to deal
    with them, because i often get database errors. the only time i use the
    last_logged_in field is only used when initially logging in, and when people
    view that persons profile. You can check it out at my site
    [url]www.digitalswordsmen.com[/url]. I guess it shouldn't be bad to make the swap, just
    hadn't really thought about it much. You should go and make an account on my
    site ;) you seem like a cool guy. But yeah... ill change it tommorow or so, if
    i have time.

    kenji776 Guest

  16. #15

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    I'll take a look.

    Well, it is handled differently than a text field, but once you get the hang
    of it, it's easy. Since you're only using it in two places the effect
    shouldn't be so bad. The one thing you will probably need to change is how you
    display the logged in date. Once the column value is a date/time, when you
    CFOUTPUT the values they will look something like this:

    2005-07-28 23:44:02

    You will probably need to use the DateFormat() function to format them the way
    you want.



    mxstu Guest

  17. #16

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    alright sounds good. Thanks for all the help man, your awsome. Ill post back if i have any probs, don't know when ill have time to test it, sunday probobly cause im going to my cabin for the weekend.
    kenji776 Guest

  18. #17

    Default Re: Hard to explain, has to do with users, last loggedin time, and my database

    Good luck. Let me know how it goes!
    mxstu Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139