Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 2nd, 2005, 04:41 PM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default find if user /ip is connected

i posted this in one section already, but i think it might not be the bast place to put it, so i'm putting it here too:
Ok, i'm new to aspx, but i'm a fast learner, real fast. but i came across a problem i haven't yet found any reference material on... and i've yet to figure it out. here's what i WANT to do: store some kind of variable in the database, that will be read from later, by another user(via the asp script) that will used to estimate if you user who's profile they're viewing is still online... OR, query the server (iis) to see if the ip addy associated with that user is still connected. i don't know what, if any, are the functions i call to see if an ip is connected, so for the last while, i've been using the now() function, to write an entry in the database, under that users name, and when you come across thier profile, it will get that value for that user out of the database, and see if it is withing five minuites of now(), and if so, they are (probably) still online. then problem with that? now() uses the CMOS clock, and not the windows settings you have, so setting it to military time won't help. ya know user1's time in the database is 12:59 (trim the am and pm) and user2 accesses user1's page at 01:01 (pm), well it's technically a smaller number, muuuuch smaller than five minuites. ok. so, is there a way (once id changed the script to write the users ip at logon, instead of the trimmed now() function), to get the users ip addy with your script? i know there HAS to be, i see all kinds of chineese example for doing that in java, but i don't write java, or read japaneese. do i need to import any other namespaces other than my oledb to get the ip function? also, not that i'll need an answer to this if you can answer my previous question, but if there is no way to do what i want, then is there a way to user the WINDOWS clock instead of the CMOS? thanks in advance. to see an example of what i'm trying to perfect, check out my site at http://www.profiles.grimmusic.com thanks again.

[email protected]
WWW.GRIMMUSIC.COM
__________________
---------------------------
A Black sheep moves easy in the darkness.
[email protected]
WWW.GRIMMUSIC.COM
 
Old February 3rd, 2005, 12:59 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

Stop cross posting the same question in MULTIPLE forums. There are many ppl here visiting more than one forums ... for them it would be really irritating.

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old February 3rd, 2005, 05:08 AM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

i don't care if it irritates you, it's not YOU i came to see. i didn't know which of the two forums to leave that particular question in, so i left it in both.

[email protected]
WWW.GRIMMUSIC.COM
 
Old February 3rd, 2005, 05:16 AM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

hmmm, that seemed a bit harsh. no offense intended, just saying that's why i left it in both, that's all. but thanks for your help in the other forum topic.

[email protected]
WWW.GRIMMUSIC.COM
 
Old February 3rd, 2005, 01:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Of course it's *us* or *me* or Vadivel you come to see. You come for an answer, right?

If you want an answer, it's not wise to irritate people. They give you an answer in their own free time without any obligation to do so.

So, although you realized your own harshness, you did come to see Vadivel or any other member of this forum....

Cheers,

Imar
 
Old February 3rd, 2005, 04:22 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

The 2 tier architecture, server-client, is the nature of web programming. Giving its nature time taken in ASP.Net (do not mistake this as ASP) will always return the server time. If you want the client time (witch the user can change between sessions) you have to use client-side programming such as JavaScript (Microsoft call this JScript). You can collect this data (client-side) through GET witch is URL attributes.
Code:
 www.myURL.org?timeNow=10:21&ID=3148t34
The JavaScript code is simple:
Code:
<script type="text/javascript">
var d = new Date()
document.write(d.getHours())
document.write(".")
document.write(d.getMinutes())
document.write(".")
document.write(d.getSeconds())
</script>
The above code just print out the time. In your case you would want to put it in an URL/URI.

Needless to say this got nothing to do with ASP.NET, even though you could just as well use the server time. The interval between seconds (and minutes and hours etc.) is exactly the same regardless server-side or client-side.

 - mega
Moving to C# .NET
 
Old February 4th, 2005, 12:54 AM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

OK, I DON'T KNOW WHY NOONE AT ANY OF THE FORUMS KNEW MUCH ABOUT THE SESSION_ONEND EVENT (OR RATHER "SUBROUTINE") OTHER THAN THE FACT THAT IT'S <b>ENTIRELY</B> UNRELIABLE. BUT I FIGURED OUT A LOT ABOUT IT, AND WHAT YOU <B>CAN</B> AND <B>CANNOT</B> DO WITH IT, BY USING A BIT OF LOGIC. I KNOW I'VE GOTTEN A LOT OF PEEOPLE WHO TRIED TO HELP ME, MOSTLY TO NO AVAIL, BECAUSE NOONE UNDERSTOOD THE CAPABILITIES, AND PARAMATER LIMITS, OF THIS EVENT, AS MUCH AS WAS REQUIRED TO IN ORDER TO RESOLVE THIS ISSUE, (WHICH I FOUND OUT, THE INTERNET FORUMS ARE <B>FILLED</B> WITH PEOPLE WANTING TO DO THE SAME THING, BUT FOR SOME REASON, NOONE WAS ABLE TO HELP, I GUESS EITHER NOONE KNOWS THIS TRICK, OR ALL THE PEOPLE WHO DO AREN'T TALKING). OK NOW, FOLLOW ALONG:
************************************************** ************
MY TUTORIAL FOR MAKING SURE THE DB ENTRY IS MADE FOR A USER WHO DID NOT LOG OUT WITH THE LOGOUT BUTTON, (EG. LEFT THE SITE, OR CLOSED THE BROWSER);
************************************************** ************
OK, NOW I KNOW FROM BEING ALL OVER THE NET, SEARCHING FOR A RESOLOUTION, BEFORE I GAVE UP AND JUST SAT HERE TILL I FIGURED IT OUT, THAT ALMOST ALL OF YOU HAVE SEEN THE VERY POPULAR CODE EXAMPLE FOR FINDING THE NUMBER OF CURRENT USERS CONNECTED, IT USES THE APPLICATION("YOUR VARIABLE NAME HERE") VARIABLE IN INCREMENT THE NUMBER OF USERS HOLDING A SESSION ID, WELL IF YOU LOOK IN THAT EXAMPLE, YOU'LL SEE THAT THE SEESION_ONEND EVENT IS ACTUALLY EXECUTING <B>SOMETHING</B>, SO YOU KNOW YOU CAN EXECUTE A SCRIPT IN IT. NOW WHAT A LOT OF PEOPLE HAVEN'T FIGURED OUT, IS THAT YOU <B>CANNOT</B> USE A REPLY OR REQUEST METHOD IN THAT EVENT. ALSO, IT IS NOT THE NETWORK SERVICE OR IUSER THAT IS USING A PERMISSION TO EXECUTE THAT EVENT, IT IS ACTUALLY THE "LAUNCH IIS PROCESS ACCOUNT (IWAM_YOURPCNAME)" SO YOU'LL HAVE TO SET THE PERMISSION SETTINGS FOR THE DIRECTORY THAT THE DB IS IN TO ALLOW THAT ACCOUNT TO EDIT IT'S CONTENTS, FOR SOMPLICITY, I ALLOWED THAT PERMISSION TO THAT ACCOUNT FRO THE WHOLE DIRECTORY CONTIANING THE DB AND THE GLOBAL.ASAX FILE. NOW, BACK TO THE COUNTER EXAMPLE, YOU SEE IN THE EXAMPLE, WHERE IT STORES, IN THE SESSION_ONSTART EVENT, A VARIABLE TO THE APPLICATION("YOURVARIABLENAME") VARIABLE? WELL YOU REMEMBER HOW IN THAT EXAMPLE, YOU CALLED TO THAT VARIABLE FROM YOUR ASP OR ASPX PAGE? EG: "<%= RESPONSE.WRITE (APPLICATION("MYVARIABLENAME").TOSTRING)?
OK, WELL NOW IF YOU THINK ABOUT IT, THAT MEANS THAT THE APPLICATION VARIABLE IS ACCESABLE OUTSIDE OF THE SESSION_ONSTART SUBROUTINE. SO THEN, WHY CANT WE USE THAT VARIABLE IN THE SESSION_ONEND SUBROUTINE, SINCE WE <b>CAN'T</B> USE SOMETHING LIKE "REQEST.COOKIE" OR "RESPONSE.REDIRECT"? WELL THE GOOD NEW IS: YOU CAN. AND HERE'S HOW I DID IT:
************************************************** ************

<%@ IMPORT NAMESPACE="SYSTEM.DATA"%>
<%@ IMPORT NAMESPACE="SYSTEM.DATA.OLEDB"%>
<%@ LANGUAGE="VBscript" %>
<script language="VB" runat="server">

Sub Application_OnStart
Application("Active")=0
End Sub

Sub Application_OnEnd
'no code is needed here
End Sub


Sub Session_OnStart
Session.Timeout=1
Session("Start")=Now
Application.Lock
Application("Active")=Application("Active")+1
dim this


IF REQUEST.Cookies ("CK") IS NOTHING THEN
RESPONSE.REDIRECT("LOGIN.ASPX")
ELSE
APPLICATION("CK") = REQUEST.Cookies ("CK")("UID").TOSTRING()
Application("uid") = REQUEST.Cookies("CK")("UID")
DIM CN222 AS new OLEDBConnection
DIM CMV222 AS STRING
DIM CM222 AS NEW OLEDBCOMMAND
CN222 = new OLEDBConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0; Data Source=Z:\WWW\MEMBERS\GRIM.mdb")
CMV222 = "UPDATE REG SET ONLINE='" & "YES" &"' WHERE UNAME = '" & Application("uid") &"'"
CM222 = NEW OLEDBCOMMAND(CMV222,CN222)
cn222.open()
CM222.EXECUTENONQUERY()
CN222.Close
CN222 = NOTHING
response.write("<BR>eeeeee<BR>" & Application("uid") )
Application("this") = Session.SessionID
END IF

Application.unlock
End Sub


Sub Session_OnEnd

DIM UID = Application("uid")
DIM CN222 AS new OLEDBConnection
DIM CMV222 AS STRING
DIM CM222 AS NEW OLEDBCOMMAND
CN222 = new OLEDBConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0; Data Source=Z:\WWW\MEMBERS\GRIM.mdb")
CMV222 = "UPDATE REG SET ONLINE='" & "no" &"' WHERE UNAME = '" & UID &"'"
CM222 = NEW OLEDBCOMMAND(CMV222,CN222)
cn222.open()
CM222.EXECUTENONQUERY()
CN222.Close
CN222 = NOTHING

Application.Lock
Application("Active")=Application("Active")-1
Application.unlock
end sub

</SCRIPT>
************************************************** ************
NOW KEEP IN MIND, I SET MY SESSION.TIMEOUT TO 1 MINUITE, SO I DIDN'T HAVE TO WAIT AS LONG TO SEE IF IT WORKED, YOU MAY WANT TO CHANGE THAT <b>AFTER</B> YOU TEST IT FOR YOURSELF, AND ARE SATISFIED THAT IT WORKS FOR YOU.
************************************************** ************
ALSO, IT IS IMPORTANT TO REMEMBER THAT I HAVE ONLY BEEN TEACHING MYSELF PROGRAMMING FOR A LITTLE OVER 2 WEEKS NOW, SO SOME PARTS OF MY EXAMPLE MAY NOT BE THE BEST PRACTICES, AND IF YOU DO FIND SOMETHING WRONG WITH IT, PLEASE REPLY TO THIS, WITH THE ERROR YOU FOUND, SO THAT OTHERS ARENT MISLEAD. I AM NOT IMPLYING THAT THIS IS A BULLETPROOF WAY TO DO THINGS, ALL I AM IMPLYING IS THAT IT WORKED FOR ME, AND EVEN IF IT'S A LITTLE INEFFICIENT, IT FITS MY NEEDS JUST FINE, CONSIDERING NOONE ESLE COULD EVEN GET IT TO WORK.
************************************************** ************
THANK YOU ALL FOR THE HELP AND MOST IMPORTANTLY, ALL THE LINKS TO VALUABLE REFERENCE MATERIAL ON THE WONDERFULL RESOURCE WE CALL THE NET.
-------------------------------------------
ALEX GRIM
HTTP://WWW.GRIMMUSIC.COM

[email protected]
WWW.GRIMMUSIC.COM
 
Old February 6th, 2005, 03:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

Because of my inconsideration I lost what I wrote, so you are gonna get the really quick and dirty answer..
Code:
<body onUnload="javaScript=alert('Call a function that make the approbiat changes in your database and check first if it's still you domain..');">
Don't use global.asax - it's gives really bad performance!

- mega
Moving to C# .NET
 
Old February 7th, 2005, 02:36 AM
Authorized User
 
Join Date: Dec 2004
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ALEX_GRIM
Default

yeah, that's what i've been hearing about global, i might look into the java function, but i'd have to study on it a bit, as i am new to ALL programming languages. thanks for your help dude.

[email protected]
WWW.GRIMMUSIC.COM





Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Country from IP? ccc_storage Classic ASP Professional 3 June 5th, 2005 10:49 AM
find if a user/ ip is connected ALEX_GRIM ASP.NET 1.0 and 1.1 Professional 6 February 4th, 2005 12:53 AM
How do i find Client IP sethumail2000 C# 0 January 27th, 2005 04:42 AM
Find Own IP akremer C# 3 September 1st, 2003 01:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.