Re: [PHP] Whos online at the moment in PHP
On Sunday, June 23, 2002, at 09:53 AM, Pag wrote: Is it possible to code in PHP a small indicator on a site saying how many people are viewing that page at the moment? Sorry if its a silly question, but i am a newbie at PHP. If it is, could you point me in the good direction? i mean, some function or something. Sorry, can't be done. People aren't really online when they are using a web browser. They request a page, and it gets sent to them, and the web server forgets about them. Unless the web server logged their request, but then the web server has no way of knowing when the user stops looking at the page, so... you get the picture. You'd have to write a Java applet or something that can maintain state. HTTP can't do this. Unless you're really creative and you use JavaScript and sessions (and even then it won't be very reliable). Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Whos online at the moment in PHP
Why not; 1. Record each visitors IP that connects and the connect time. 2. Delete from this table all records that are 5 mins old. 3. Count the remaining records as people currently viewing page. James -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whos online at the moment in PHP
Well, traditionally this would be done with sessions, and it's not exactly the easiest topic for a newbie to get their head around. It also never going to be a science -- how do you know when a user closes their browser window or click onto another page? You need to have clean-out routines for logged in users who haven't had any activity for a while and all sorts of other goodies. Traditionally, most sites achieve things like 45 users and 12 guests online kinda thing using sessions, but I don't know if I've seen 45 users looking this page right now anywhere. Hrm... a VERY NON SCIENTIFIC approach on a page-by-page basis would be to log each hit on the page, and the time() that the hit was... boldly assume that people will look at your page for 30 seconds or something, and keep a counter of all hits within the last 30 seconds. Like I said, not very geek at all, not in any way scientific, but it's a quick fake. Essentially, it's more of a counter saying 48 hits in the last 30 seconds than 48 people looking at this page right now. If you want to achieve this properly though, it's going to take you a few hours to get your head around sessions, which can only be a good learning experience any way. Justin French on 23/06/02 11:53 PM, Pag ([EMAIL PROTECTED]) wrote: Is it possible to code in PHP a small indicator on a site saying how many people are viewing that page at the moment? Sorry if its a silly question, but i am a newbie at PHP. If it is, could you point me in the good direction? i mean, some function or something. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whos online at the moment in PHP
Most questions like this depend more on your ability to think creatively than your experience with PHP, so don't let inexperience discourage you from exploring on your own. First, decide what you consider to be online exactly. If I, for example, requested a page 30 seconds ago, you would probably consider me to be online, even though I could theoretically have closed my browser and gone to dinner since then. If you're familiar with using a database, consider using the PHPSESSID (look into PHP sessions for more information on this) as a primary key in a table where the timestamp is kept and updated on each page request. To determine who is online, you could simply run a query on this table using your threshhold of idle time that you've determined to count as online. There are plenty of different ways to approach this, and my early-morning example is probably not the best. Hopefully it gives you an idea though of what you need to accomplish. Chris Pag wrote: Is it possible to code in PHP a small indicator on a site saying how many people are viewing that page at the moment? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Whos online at the moment in PHP
Hi, I've ma some atuh system to do such thing beside other special functions, u have to store some session ids in some db and then refresh timestamp for those session wich is still active other delete after 30min or some other time. -- bye, Urosmailto:[EMAIL PROTECTED] Sunday, June 23, 2002, 3:53:46 PM, you wrote: P Is it possible to code in PHP a small indicator on a site saying how many P people are viewing that page at the moment? P Sorry if its a silly question, but i am a newbie at PHP. If it is, could P you point me in the good direction? i mean, some function or something. P Thanks. P Pag -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php