cs_bugzilla79
Messages postés9Date d'inscriptionlundi 20 janvier 2003StatutMembreDernière intervention20 mai 2005
-
20 janv. 2003 à 11:40
cs_bugzilla79
Messages postés9Date d'inscriptionlundi 20 janvier 2003StatutMembreDernière intervention20 mai 2005
-
20 mai 2005 à 15:23
bonjour @ tous, je cherche le moyen de lister tous les session.sessionID en cours sur mon site.
qq'un connait le moyen de faire ça ?
shaiulud
Messages postés404Date d'inscriptionmardi 18 décembre 2001StatutMembreDernière intervention15 juillet 201422 21 janv. 2003 à 11:25
<%'global.asa%>
<OBJECT RUNAT= Server
SCOPE=Application
ID=ListSession
PROGID="Scripting.Dictionary">
</OBJECT>
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
Sub Session_OnStart
Application.Lock()
Application("NB_USERS")= CLng(Application("NB_USERS")) +1
Application.StaticObjects.Item("ListSession").Add Cstr(Session.SessionId), Cstr(Session.SessionId)
Application.UnLock()
End Sub
Sub Session_OnEnd
Application.Lock()
if Application("NB_USERS")>0 then
Application("NB_USERS")= CLng(Application("NB_USERS")) - 1
else
Application("NB_USERS")=0
end if
Application.StaticObjects.Item("ListSession").Remove(CStr(Session.SessionId))
Application.UnLock()
End Sub
</SCRIPT>
<%'default.asp%>
<%
Sub ListSessionID
Dim arUserNames, arUserIDs, i, userName
arUserIDs = Application.StaticObjects.Item("ListSession").Keys
arUserNames = Application.StaticObjects.Item("ListSession").Items
For i = 0 To Application.StaticObjects.Item("ListSession").Count-1
If (Session.SessionID = arUserIDs(i)) Then
userName = " " & arUserNames(i) & " "
Else
userName = arUserNames(i)
End If
Response.Write "<tr><td>"& userName &"</td></tr>"
Next
End Sub
response.write "Session en Cours :"& Session.SessionID
%>
cs_bugzilla79
Messages postés9Date d'inscriptionlundi 20 janvier 2003StatutMembreDernière intervention20 mai 2005 23 janv. 2003 à 10:48
merci !
mais y'a pas un moyen de faire autrement qu'avec le global.asa ? j'ai l'impression que ça déconne chez moi, la dernière fois que j'ai testé, ça ne fonctionnais absolument pas (j'avais testé un script d'un tutorial).
cs_bugzilla79
Messages postés9Date d'inscriptionlundi 20 janvier 2003StatutMembreDernière intervention20 mai 2005 20 mai 2005 à 11:43
Bon, je reviens un peu vers ce topic. Je m'étais un peu inspiré de vos conseils pour pondre ce code. Au vu du code de Shaiulud, j'ai tenté d'accéder au Session.SessionID dans la Sub Session_OnEnd.
Manque de pot, on dirait qu'à la fin de la session, le SessionID n'est plus dispo. C'est une impression ou pas ?!
Pour rappel et pour illustrer mes propos, le code de Shaiulud dit :
Application.StaticObjects.Item("ListSession").Remove(CStr(Session.SessionId))
Ce qui sous-entend que le SessionID est tjs dispo dans Session_OnEnd.
Voici mon fameux code compris dans mon global.asa :
<script language="VBScript" runat="Server"> Sub Session_OnEnd
Application.Lock()
'---------- Vidage du panier
Set connVidePanier = CreateObject("ADODB.Connection")
connVidePanier.Open [ma chaine de connexion à la base de données]
connVidePanier.Execute("Delete * From Panier Where Pan_Session = '" & Session.SessionID & "'")
connVidePanier.Close
Set connVidePanier = Nothing
en gros, ça explique pourquoi les événements sur Session_OnEnd et sur
Application_OnEnd, ça marche mal ou du moins pourquoi on peut pas
récupérer de messages d'erreur... Super !!!
Quick Tips
<hr color="#0000ff" size="3">
Global.asa OnEnd Events Don't Run
<hr>
I continually get questions concerning the Application_OnEnd
and Session_OnEnd event handlers in global.asa not running.
The problem is usually not that the server isn't set up right
or that it's broken. It's usually something much simpler.
What developers tend to forget that the OnEnd events have no
way to tell you when something's wrong. This is understandable
since all the other pages on a web site and even the
Application_OnStart and Session_OnStart don't have this problem.
It stems from the fact that the OnEnd events execute long
after the user has
left so there's no browser to send an error message to.
As a result, you might never know there's a problem with your
code and the smallest bug or typo can cause the whole
routine to not execute at all.
Because of this, you really need to be extra careful when writing
or modifying code for these particular subroutines. I
recommend adding a set of code with noticable results at the
end of the routine during testing. For live code, some decent
error handling will help catch those run time errors that
seem to "just happen" on their own.