www.webdeveloper.com
Results 1 to 2 of 2

Thread: Online Users Script Not working

  1. #1
    Join Date
    Apr 2009
    Posts
    66

    Post Online Users Script Not working

    Hey everybody,

    I have a problem:this script won't work and being new to asp, I don't know what is wrong.

    global.asa
    Code:
    <Object Runat="Server" Scope="application" ID="dOnlineUsers" ProgID="Scripting.Dictionary"></Object>
    
    <SCRIPT LANGUAGE=VBScript RUNAT=Server>
    
    sub Application_OnStart
        application("ServerStart") = now
    end sub
    
    function Decrypt(sText)
        'Replace with your own decrypt ;)
        Decrypt = sText
    end function    
    
    function adZero(sText)
        'Adds zeros to the beginning
        if isNull(sText) then exit function
        adZero = string(5 - len(sText), "0") & sText
    end function
    
    Sub Session_OnStart
    
        'Session_OnStart is automatically called by the ASP Interpreter
        'when a new session starts. (Probably a new visitor)
    
        'TimeOut value determines the period in minutes when 
        'the session is assumed to be abandoned
    
        Session.TimeOut = 10
    
        'Get the current active users list
        sActiveUsersList = application("ActiveUsersList")
        
        'Get the new user name from the cookie
        sNewUserName = Decrypt(request.cookies("devUserName"))
        
        'If the visitor doesn't have a registered username, assign Guest(n) label
        if sNewUserName = "" then sNewUserName = "Guest-" & AdZero(CInt(application("Visitors")))
        
        'Initial action time
        sLastActionTime = Time
        
        'User info consists of user name, last action time, and the page viewed
        sUserInfo = sNewUserName & "<|>" & sLastActionTime & "<|>" & sLastPageViewed
    
        'Add this user to our collection with SessionID being the key
        '(See the top of this file to see how dOnlineUsers object is initiated)
        dOnlineUsers.Add Session.SessionID, sUserInfo
        
        'Lock the application variable and update the contents
        application.lock
        'The number of active users
        application("ActiveUsers") = application("ActiveUsers") + 1
        'The number of visitors since last application reset
        application("Visitors") = application("Visitors") + 1
        
        'If the date is different than the previously stored date,
        'it means we passed midnight, so reset our "today" counters
        if application("TodaysDate") <> Date() then
            application("PageViewsToday") = 0
            application("VisitorsToday") = 0
        end if
        application("VisitorsToday") = application("VisitorsToday") + 1
        'Store the date
        application("TodaysDate") = Date()
        'Unlock and go
        application.unlock
        
    End Sub
    
    Sub Session_OnEnd
        'Session_OnEnd is automatically called by the ASP Interpreter
        'when the specified TimeOut period has passed after user's last action
    
        on error resume next
    
        'Remove this session from our collection
        dOnlineUsers.Remove Session.SessionID
        
        'And update the application variables
        application.lock
        application("ActiveUsers") = application("ActiveUsers") - 1
        application.unlock
    
    End Sub
    </SCRIPT>
    whoson.asp
    Code:
    <html><title>Who is Online</title><body>
    <p>
    Who is Online
    </p>
    
        <%
        on error resume next
        response.write "<table cellpadding=""2"" cellspacing=""1"" border=""0"" width=""100%"">"        
        response.write "<tr><td></td><td><strong>Who</strong></td><td><strong>When</strong></td><td><strong>Where</strong></td></tr>"
        aSessions = dOnlineUsers.Keys
        for iUser = 0 to dOnlineUsers.Count - 1
            sKey = aSessions(iUser)
            sUserInfo = dOnlineUsers.Item(sKey)
            aUserInfo = split(sUserInfo, "<|>")
            
            sUserName = aUserInfo(0)
            sLastActionTime = aUserInfo(1)
            sLastPageViewed = aUserInfo(2)
            
            if sUserInfo <> "" then
            iUsrCount = iUsrCount + 1
            response.write "<tr><td align=""right"">" & iUsrCount & ".</td><td> " & sUserName & "</td><td>" & sLastActionTime & "</td>"
            response.write "<td>" & sLastPageViewed & "</td></tr>"
            end if
            
        next
        response.write "</table>"
        %>
    
    <br><br>
    </body></html>
    _onlineusers.asp
    Code:
    <%
    
    function Decrypt(sText)
        'Replace with your own decrypt ;)
        Decrypt = sText
    end function    
    
    
        application.lock
        application("PageViews") = application("PageViews") + 1
        if application("TodaysDate") <> Date() then
            application("PageViewsToday") = 0
            application("VisitorsToday") = 0
        end if
        application("PageViewsToday") = application("PageViewsToday") + 1
        application("TodaysDate") = Date()
        application.unlock
        
        if session("devUserName") = "" then
            session("devUserName") = Decrypt(request.cookies("devUserName"))
            session("devFullName") = Decrypt(request.cookies("devFullName"))
        end if
    
        session("PageViewed2") = session("PageViewed1")
        session("PageViewed1") = session("PageViewed0")
        session("PageViewed0") = request.ServerVariables("script_name")
        
        sUserInfo = dOnlineUsers.Item(Session.SessionID)
        aUserInfo = split(sUserInfo, "<|>")
        aUserInfo(1) = Time()
        aUserInfo(2) = request.ServerVariables("script_name")
        sUserInfo = aUserInfo(0) & "<|>" & aUserInfo(1) & "<|>" & aUserInfo(2)
        dOnlineUsers.Item(Session.SessionID) = sUserInfo
        
        
    %>

  2. #2
    Join Date
    Apr 2009
    Posts
    66
    HUm... I think I found the problem: the decrypt function.

    But by what am I supposed to replace it?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles