PHP Code:
<?php
require('path/to/config.php');
$db = mysql_connect($servername,$dbusername,$dbpassword) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
unset($servername,$dbusername,$dbpassword,$dbname);
$query = mysql_query("SELECT count(*) as count FROM session WHERE lastactivity > ". (time()-3600) ) or die(mysql_error()); //one hour
list($num_online) = mysql_fetch_array($query);
mysql_free_result($query);
mysql_close($db);
echo $num_online;
?>