the example 2 is not correct.
it should use the lusers command for this
i have created a working example:
include_once('./SmartIRC.php');
$irc = &new Net_SmartIRC();
$irc->setDebug(SMARTIRC_NONE);
$irc->setUseSockets(FALSE);
$irc->setBenchmark(FALSE);
$irc->connect('myserver.org', 6667);
$irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.
SMARTIRC_VERSION.' (example2.php)', 0, 'Net_SmartIRC')
;
$irc->_send('lusers');
$irc->getList('#mychannel');
$resultar = $irc->listenFor(SMARTIRC_TYPE_INFO);
$irc->disconnect();
if (is_array($resultar)) {
$resultex = explode(' ', $resultar[2]);
$count = $resultex[2];
$count--;
$time = time();
echo"<B>On #mychannel are $count
Users</B><br>";
if ($count > 0){
$root = "/some/dir/";
$file = $root . "/make/this/file.php";
$fd = fopen($file, "w");
$content .= "<? \n // users count on
#mychannel\n";
$content .= "\$Time = $time;\n";
$content .= "\$UserCount= $count;\n";
$content .= "\n ?> \n";
fwrite($fd, $content);
fclose($fd);
}else{
echo "count is not correct ($count)\n";
}
} else {
?>
<B>An error occured, please check the specified
server and settings<B>
<?
}
i also attached the file
CountUsers.php aka example2.php version 1.4
Logged In: NO
i made a mistake.. that was for the whole server (didn't made
any difference for me, but anyway here is the correct one, but
it only shows the visable users)
<?php
/**
* $Id: example2.php,v 1.3 2003/01/16 22:30:23 meebey Exp
$
* $Revision: 1.41 $
* $Author: meebey $
* $Author2: Madcat $
* $Date: 2004/05/10 03:40:00 $
*
* Copyright (c) 2002-2003 Mirco "MEEBEY" Bauer
<mail@meebey.net> <http://www.meebey.net>
*
* Full LGPL License: <http://www.meebey.net/lgpl.txt>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
either
* version 2.1 of the License, or (at your option) any later
version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied
warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
Public
* License along with this library; if not, write to the Free
Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
*/
// ---EXAMPLE OF HOW TO USE Net_SmartIRC---
// this code shows how you could show on your homepage
how many users are in a specific channel
// PS this only shows the amount of users who are not
invisable (+1 flag)
include_once('./SmartIRC.php');
$server = "yourserver.org";
$kanaal= "#yourchannel";
class mybot
{
function quit(&$irc, &$ircdata) //just incase
we have to kill him :)
{
$irc->quit("time to say goodbye...");
$irc->disconnect();
echo "end of script";
exit;
}
}
$bot = &new mybot();
$irc = &new Net_SmartIRC();
$irc->setDebug(SMARTIRC_NONE); // we do
not want any debug
//$irc->setDebug(SMARTIRC_DEBUG_IRCMESSAGES);
// we only want to see what a normal user sees
//$irc->setDebug(SMARTIRC_DEBUG_ALL); //
heavy debugging mode
$irc->setUseSockets(false); // i forgot to
compile with sockets
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!
quit', $bot, 'quit');
$irc->connect($server, 6667); //connect to
server
$irc->login('Net_Smart', 'Net_SmartIRC Client '.
SMARTIRC_VERSION.' (read user list)', 8, 'Net_Smart'); // login
$irc->_send('MODE Net_Smart +i'); // make me
invisable
$irc->_send('names '.$kanaal); // show me
who is online on this channel
$resultar = $irc->listenFor(SMARTIRC_TYPE_NAME); //
fetch names
$resultex = explode(' ', $resultar[0]); // give me
the first line
$size = sizeof($resultex); // how many users
are there?
$time = time(); //at what time did i look?
if ($size > 0){ //did i got any result
or was it nonsense?
$root = "/some/dir"; // we would like
to make an include file with this data
$file = $root . "/inc/some/name.php";
$fd = fopen($file, "w"); // we have to write
a file
$content .= "<? \n //total users on $kanaal\n"; //
make a header
$content .= "\$IRCTime = $time;\n"; // store
the time
$content .= "\$IRCTotalUsers = $size;\n"; // store
the amount of visable users
for($i=0;$i<$size;$i++){ //check for all
users the name
$content .= "\$IRCNameUser[$i] = ".
$resultex[$i]." ;\n";
} // and store it
$content .= "\n ?> \n"; //close php tag
fwrite($fd, $content); //write all data
to the file
fclose($fd); //close the file and we
are ready to rock
}else{
echo "size is not correct ($size)\n"; //if the
server was to busy or something like that
} // put something in out logfile
$irc->quit("time to say goodbye..."); // bye bye
$irc->disconnect(); // i'll miss you too...
exit; // end of php
?>
Logged In: NO
This one realy shows all visable users, the above posted one,
only shows the amount of users on the server (it didn't made
any differense at my side)
<?php
/**
* $Id: example2.php,v 1.3 2003/01/16 22:30:23 meebey Exp
$
* $Revision: 1.41 $
* $Author: meebey $
* $Author2: Madcat $
* $Date: 2004/05/10 03:40:00 $
*
* Copyright (c) 2002-2003 Mirco "MEEBEY" Bauer
<mail@meebey.net> <http://www.meebey.net>
*
* Full LGPL License: <http://www.meebey.net/lgpl.txt>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
either
* version 2.1 of the License, or (at your option) any later
version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied
warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
Public
* License along with this library; if not, write to the Free
Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
*/
// ---EXAMPLE OF HOW TO USE Net_SmartIRC---
// this code shows how you could show on your homepage
how many users are in a specific channel
// PS this only shows the amount of users who are not
invisable (+1 flag)
include_once('./SmartIRC.php');
$server = "yourserver.org";
$kanaal= "#yourchannel";
class mybot
{
function quit(&$irc, &$ircdata) //just incase
we have to kill him :)
{
$irc->quit("time to say goodbye...");
$irc->disconnect();
echo "end of script";
exit;
}
}
$bot = &new mybot();
$irc = &new Net_SmartIRC();
$irc->setDebug(SMARTIRC_NONE); // we do
not want any debug
//$irc->setDebug(SMARTIRC_DEBUG_IRCMESSAGES);
// we only want to see what a normal user sees
//$irc->setDebug(SMARTIRC_DEBUG_ALL); //
heavy debugging mode
$irc->setUseSockets(false); // i forgot to
compile with sockets
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!
quit', $bot, 'quit');
$irc->connect($server, 6667); //connect to
server
$irc->login('Net_Smart', 'Net_SmartIRC Client '.
SMARTIRC_VERSION.' (read user list)', 8, 'Net_Smart'); // login
$irc->_send('MODE Net_Smart +i'); // make me
invisable
$irc->_send('names '.$kanaal); // show me
who is online on this channel
$resultar = $irc->listenFor(SMARTIRC_TYPE_NAME); //
fetch names
$resultex = explode(' ', $resultar[0]); // give me
the first line
$size = sizeof($resultex); // how many users
are there?
$time = time(); //at what time did i look?
if ($size > 0){ //did i got any result
or was it nonsense?
$root = "/some/dir"; // we would like
to make an include file with this data
$file = $root . "/inc/some/name.php";
$fd = fopen($file, "w"); // we have to write
a file
$content .= "<? \n //total users on $kanaal\n"; //
make a header
$content .= "\$IRCTime = $time;\n"; // store
the time
$content .= "\$IRCTotalUsers = $size;\n"; // store
the amount of visable users
for($i=0;$i<$size;$i++){ //check for all
users the name
$content .= "\$IRCNameUser[$i] = ".
$resultex[$i]." ;\n";
} // and store it
$content .= "\n ?> \n"; //close php tag
fwrite($fd, $content); //write all data
to the file
fclose($fd); //close the file and we
are ready to rock
}else{
echo "size is not correct ($size)\n"; //if the
server was to busy or something like that
} // put something in out logfile
$irc->quit("time to say goodbye..."); // bye bye
$irc->disconnect(); // i'll miss you too...
exit; // end of php
?>