Sunday, November 06, 2011

IRC - Get the user count of a channel in plain text with Denora/PHPDenora/

You need to have Denora and PHPDenora installed and running on your IRCd for this to work.

<?php
define("_VALID_PARENT", 1);
require ("libs/phpdenora/init.php");  //You have to provide the proper path to the file here
$link = sql_db_connect();
$channelcount = sql_fetch_array(sql_query("SELECT currentusers FROM ".$denora_chan_db." WHERE channel LIKE \"".mysql_real_escape_string(trim($_GET["channel"], '"'))."\";"));
if ($channelcount[0] == "") {
    $channelcount[0] = 0;
}
header("Content-type: text/plain");
echo $channelcount[0];
sql_db_close($link);
?>

It works like this : http://stats.yournetwork.net/usercount.php?channel=%23youchannel

In PHP, you will probably want to use something like this :
$usercount = file_get_contents("http://stats.yournetwork.net/usercount.php?channel=%23yourchannel");

The great thing with this is that you can now use some PHP to serve your users a user count badge for their channel.

See also : http://whatnwhat.blogspot.com/2011/11/irc-get-user-list-of-channel-in-json.html

No comments:

Post a Comment