|
#1
|
|||
|
|||
|
Allright so i have a chatroom in which you can click "Logout" and you are then logged out and your name is taken off of the list of people currently in the chatroom. However, if you do not click Logout, and simply close the window, the session variable isn't destroyed and your name is not taken off the list because PHP doesn't do event based functions. At least thats what i think.
So here's my question: Is there a way to, for example, call function Logout() in PHP when the window closes? Or should i use javascript like this: Code:
<script language="javascript">
document.onUnload = document.write('<?php Logout();?>');
</script>
Anyway, any help on this would be great. Thanks. |
|
#2
|
||||
|
||||
|
That won't work at all, since the PHP is executed before the Javascript, so Logout() will be run every time the page is loaded
It's window, but as with window.onload, I think document.onunload has the same effect (note the case).To do this, you must devise a fairly complex system whereby the last-seen time of each user is stored, and set a reasonable timelimit after which any page accesses (by anyone) will log that user out.
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP! |
|
#3
|
|||
|
|||
|
Oh boy.
I think i've got myself into something way over my head. Could you show me an example Twey, please? Thanks. |
|
#4
|
||||
|
||||
|
http://twey.co.uk/files/chat.phps
It's an actual script I wrote for someone else, so it's a little more complex than it needs to be for an example, but I'm sure you can pick out the relevant bits.
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP! |
|
#5
|
|||
|
|||
|
Holy cow...how long did it take you to write that?
Oh, and thanks.
|
|
#6
|
||||
|
||||
|
I don't know, I just wrote it between other things, like everything I do on this forum.
It's not that big
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP! |
|
#7
|
|||
|
|||
|
Allright Twey, I've finally gotten to a point in my process of learning PHP & MySQL that i can read through your chat script that you provided, and find the necessary step to achieve what I'm going for here. I did read it and i now have the basic idea of what i'm doing, but theres one thing i wanted to ask you.
Code:
mysql_query("select * from $usertable where logged=1 and DATE_SUB(NOW(),INTERVAL 30 SECOND) > lastseen;");
Thanks.
|
|
#8
|
|||
|
|||
|
Anybody have an answer?
|
|
#9
|
||||
|
||||
|
Quote:
It subtracts one date from another. INTERVAL 30 SECOND returns a DATETIME object to the value of 30 seconds.
__________________
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP! |
|
#10
|
|||
|
|||
|
OOOoooohhhhhhhhh.
Its all starting to make sense now .I think i got this under control now. Thanks Twey. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
|
|