shadowayex Posted May 29, 2008 Share Posted May 29, 2008 I was wondering if it was possible to use the onload and onunload options to start mysql queries. The reason I want to do this is I want to keep track of when a user comes to a page and leaves a page (like the deals this forum has that tell us who's browsing in the forum). Link to comment Share on other sites More sharing options...
Fukushousha Posted May 29, 2008 Share Posted May 29, 2008 This thing about the forum monitoring you are mentioning is a feature of the phpBB forum. Unless I am mistaken w3schools must be using phpBB. So they do it with php, not JScript. Now ... I am not an expert so don't take my word for it but I don't think you can do such a thing since Javascript is browser-side scripting and not server-side and I do not think there is any way around it.I mean .. imagine someone with malicious intentions checking your .js file and seeing your database password >_< Link to comment Share on other sites More sharing options...
shadowayex Posted May 29, 2008 Author Share Posted May 29, 2008 This thing about the forum monitoring you are mentioning is a feature of the phpBB forum. Unless I am mistaken w3schools must be using phpBB. So they do it with php, not JScript. Now ... I am not an expert so don't take my word for it but I don't think you can do such a thing since Javascript is browser-side scripting and not server-side and I do not think there is any way around it.I mean .. imagine someone with malicious intentions checking your .js file and seeing your database password >_<True true... Then how do that do it. I wanna know T_T. Link to comment Share on other sites More sharing options...
Fukushousha Posted May 29, 2008 Share Posted May 29, 2008 I can only reccomend the hard way. Study the phpBB code. You can learn A LOT by studying it and understanding it segment by segment. You can get it here Link to comment Share on other sites More sharing options...
Jesdisciple Posted May 29, 2008 Share Posted May 29, 2008 It would be possible although kinda hard to secure, but maybe something like a session variable would work. When the page is requested, have PHP log a random hash, the current timestamp, and any other info in the database, leaving a second timestamp field empty. Drop the random string into the JavaScript so it will send it back to the server via AJAX onunload. When the AJAX call is executed, check whether a timestamp field corresponding to the hash is still empty; if it is, fill it with the current timestamp. Link to comment Share on other sites More sharing options...
jesh Posted May 29, 2008 Share Posted May 29, 2008 If I'm not mistaken, this forum takes the timestamp on the server on each page load. Then, to determine who is currently browsing the forum, they select from the database all the users with timestamps that are within the last 15 minutes. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 29, 2008 Share Posted May 29, 2008 Also, this forum uses the Invision service, not phpbb. But yeah, every time the page loads when it checks if you're logged in it also records the time and where you are. If you want to use Javascript to do something like that (which isn't necessary because PHP does it just fine), then you can have Javascript send an AJAX request to a PHP script on the server to update that. Link to comment Share on other sites More sharing options...
shadowayex Posted May 29, 2008 Author Share Posted May 29, 2008 Yeah I figured out how to do it strictly PHP. My solution was to start the page with a query that updates a field in my database called LastActive with a timestamp. Then I have queries that select users that have been active for the past 15 minutes. I wanted to make it so if the user closed out of the site or logged out, it'd send a query to an added database field starting whether they are online or not, but I don't know how to make it send the query when the page is closed. That's where the JavaScript idea came from. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 29, 2008 Share Posted May 29, 2008 You can't guarantee that will happen at all, the timestamp is the best solution for something like HTTP. Link to comment Share on other sites More sharing options...
shadowayex Posted May 29, 2008 Author Share Posted May 29, 2008 You can't guarantee that will happen at all, the timestamp is the best solution for something like HTTP.So my solution's the best way to manage it? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 29, 2008 Share Posted May 29, 2008 Most people use the timestamp, yes. If you look at the custom session handler that I set up it uses the same method. Link to comment Share on other sites More sharing options...
shadowayex Posted May 29, 2008 Author Share Posted May 29, 2008 Wow, I answered my own question right. That's a first . Thanks for the support. We should start paying you . Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.