|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Finding How Many Users Are On Your Site With PHP If you have any questions or comments on this article then please post them here.
You can read the article here . |
|
#2
|
|||
|
|||
|
Maybe there shoulda been a file to delete the entries after a certain amount of time. I know it's easy to implement but newbies might miss it completely and end up with a huge table of users.
Otherwise a great article. ![]() |
|
#3
|
|||
|
|||
|
How would I make a script that deletes all th entries b4 a certain date... automactically say every 14days..
|
|
#4
|
|||
|
|||
|
actually all entries b4 todays date..
|
|
#5
|
|||
|
|||
|
i dont have time to write the actuall code for it, but the method i would use would be a text file,
for example (this is not in php, just a genralisation) if(filedate = todaysdate) then database has already been scaned for old entries else remove old entries update file date to today end something like that should do the job, only needs basic php to do hope it helps you get an idea |
|
#6
|
|||
|
|||
|
<?php
require("../connect.php"); $today = date("mdGis"); // 0431225208 $result = mysql_query("delete from usersOnline where dateAdded < '$today'"); ?> Hehehehe I thought that up myself lol piece of cake! ![]() |
|
#7
|
|||
|
|||
|
lol, that would work 2 heheh
|
|
#8
|
|||
|
|||
|
Great code ! Here is the code I'm using on my site.
<CODE> # variables $timestamp = time(); $timeoutseconds = 300; $timeout = $timestamp-$timeoutseconds; # connect to db mysql_connect("localhost", "username", "password"); mysql_select_db("database"); # delete previous entry $delete = mysql_query("DELETE FROM users_online WHERE timestamp < $timeout OR ip = '$REMOTE_ADDR'"); if(!($delete)) print "Erreur"; # add current visit $insert = mysql_query("INSERT INTO users_online VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')"); if(!($insert)) print "Erreur"; # query database $result = mysql_query("SELECT ip FROM users_online"); if(!($result)) print "Erreur"; # get number of users and close connection $nb_users = mysql_num_rows($result); mysql_free_result($result); mysql_close(); $users_string = "$nb_users utilisateur(s) en-ligne"; </CODE> And then I can just use <? echo $users_string; ?> where I want the script to output the number of users online. Might not be the best version but works great for me ! Let me know what you think. Cheers ![]() |
|
#9
|
|||
|
|||
|
Not working.
URL
No matter how many people view it, it shows "1" person.. Help.. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > Article Discussion: Finding How Many Users Are On Your Site With PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|