Limit Users page views per day

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dnleeb
    New Member
    • Aug 2007
    • 4

    Limit Users page views per day

    Hi there,

    I'm trying to redirect a user at login if they have logged in 3 or more times in one day. I'm pretty new to asp and cant find anything to track individual users logins that will reset at the end of every day. Let me know if you have any advice.

    Thanks
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Originally posted by dnleeb
    Hi there,

    I'm trying to redirect a user at login if they have logged in 3 or more times in one day. I'm pretty new to asp and cant find anything to track individual users logins that will reset at the end of every day. Let me know if you have any advice.

    Thanks
    It might be easiest to do with cookies, using a db would be surer (cookies aren't 100% reliable) but slower and take more server power. make sure you set the cookie expire attribute to be a day, then send a cookie to the user during the log in that counts the number of logins. If that number is greater than 3, refuse the login. Let me know if this helps.

    Jared

    Comment

    • ilearneditonline
      Recognized Expert New Member
      • Jul 2007
      • 130

      #3
      Originally posted by jhardman
      It might be easiest to do with cookies, using a db would be surer (cookies aren't 100% reliable) but slower and take more server power. make sure you set the cookie expire attribute to be a day, then send a cookie to the user during the log in that counts the number of logins. If that number is greater than 3, refuse the login. Let me know if this helps.

      Jared
      Depending on the environment you are in, this may not work. For example, I have 3 PC running right now. If you use cookies, I could actually get in 9 times a day. Like Jared says, db is surer because it doesn't depend on a user pc. But depending on the size of the site, that could really slow it down.

      Comment

      • dnleeb
        New Member
        • Aug 2007
        • 4

        #4
        Thanks, how do i use the db to limit the page views?
        Sorry... I'm pretty new to all of this


        Originally posted by jhardman
        It might be easiest to do with cookies, using a db would be surer (cookies aren't 100% reliable) but slower and take more server power. make sure you set the cookie expire attribute to be a day, then send a cookie to the user during the log in that counts the number of logins. If that number is greater than 3, refuse the login. Let me know if this helps.

        Jared

        Comment

        • JamieHowarth0
          Recognized Expert Contributor
          • May 2007
          • 537

          #5
          In pseudo-code (with a bit of real ASP code in there), you'd do it like this:

          Code:
          Sub DoLogin
               Set objDbConn = Server.CreateObject("ADODB.Connection")
               strConn = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/youraccessdb.mdb")
               objDbConn.Open strConn
          
               Set rsLoginUser = Server.CreateObject("ADODB.Connection")
               strSQL = "SELECT * FROM tbl_Users WHERE EmailAddy = " & Request.Form("login_email")
               rsLoginUser.Open strSQL, objDbConn, 1, 1
          
               If rsLoginUser.RecordCount > 0 Then
                   ' Found a user!
                   If rsLoginUser("UserPW") = Request.Form("login_pw") Then
                           'Login OK, check daily login limit
                           If CInt(rsLoginUser("DailyCounter")) < 3 Then
                                 'Login OK, add 1 to Login count
                                 rsLoginUser.Update "DailyCounter", rsLoginUser("DailyCounter") + 1
                           Else
                                 'Login OK but count not, kick user
                           End If
                   Else
                         'Dud password, kick user
                   End If
               Else
                    ' Dud email, kick user
               End If
          End Sub
          Don't quote me on the ADO method of updating the number of logins though - normally I'd use a quick SQL Update query to do it myself but that's my personal perference.

          I definitely agree with mods though - DB is much better than using cookies - imagine someone in an empty web cafe... lol. Or worse - someone that's simply disabled cookies - or clears them at end of every session.

          Hope it helps!

          Comment

          • dnleeb
            New Member
            • Aug 2007
            • 4

            #6
            Thanks... this seems like it'll work

            Comment

            Working...