Post: [vb][Source] Online Users with PHP Script
05-10-2011, 03:29 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); first, you will need to make a new MySql database names 'onlinelist' (or rename it in script...)
then edit the script with your database login info, and host info
then simply make a new .php file which contains the edited script:
    <?PHP
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();
$expires = time()+600;

mysql_connect('localhost','root',''Winky Winky;
mysql_selectdb('onlinelist'Winky Winky;

$prequery = "
CREATE TABLE if not exists `onlinelist` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`expires` int(11) DEFAULT NULL,
`ip` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2620756 DEFAULT CHARSET=latin1;
";
mysql_query($prequery);

$query2 = "DELETE FROM onlinelist WHERE ip = '$ip'";
mysql_query($query2);

$query3 = "DELETE FROM onlinelist WHERE expires < '$time'";
mysql_query($query3);

$sql = "
INSERT INTO onlinelist (expires,ip)
VALUES ('$expires', '$ip'Winky Winky
";

mysql_query($sql);

$result = mysql_query("SELECT * FROM onlinelist");
$num_rows = mysql_num_rows($result);
echo $num_rows;


?>


Note that timeout is 600 seconds, you can change it to anything you want (60 would be 1 minute, 120 2 minutes....)

Now the part in your program:

You want to make a timer, or something what will periodically update the script (and get the online number), and do a simple webrequest on the script, without any POST/GET data:
    Uri site = new Uri("https://127.0.0.1/online.php");
WebRequest wReq = WebRequest.Create(site);
WebResponse wResp = wReq.GetResponse();
Stream respStream = wResp.GetResponseStream();
StreamReader reader = new StreamReader(respStream, Encoding.ASCII);
string online_users = reader.ReadToEnd();


That code will both get the users, and add the user to the list, so, if you only want to add users to the list, the code is the same, just don't display the string

It's pretty much simple as that

If you use it, i would appreciate if you'd give credits!
(adsbygoogle = window.adsbygoogle || []).push({});

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo