Page 1 of 1

php bot cant connect

Posted: Wed Feb 20, 2008 6:22 pm
by wescooldude3
i am using a php bot

// No execution Time limit

// Opening the socket to the Rizon network
$socket = fsockopen("", 6667) or die('Could not connect to the server');

// Send auth info
$nick = 'ellis-bot2';

fputs($socket,"USER CMbot CM :CM bot\n");
fputs($socket,"NICK $nick\n");

// Join a channel
fputs($socket,"JOIN #wes\n");

// Endless loop until exit.
// Continue the rest of the script here
while($data = fgets($socket, 128))
echo nl2br($data);

// Separate all data
$ex = explode(' ', $data);

// Respond to PING W/ PONG
if($ex[0] == "PING")
fputs($socket, "PONG ".$ex[1]."\n");

// Say something in the channel
$command = str_replace(array(chr(10), chr(13)), '', $ex[3]);

case ':!sayit':
if($ex[2] != $nick)
$to = $ex[2];
$arr = explode('!', $ex[0]);
$to = ltrim($arr[0],':');

fputs($socket, "PRIVMSG $to irc bot tutorial!\n");

case ':!dienow':
fputs($socket,"PRIVMSG ".$ex[2]." Goodbye cruel world!\n");

die('Session ended.');


echo '<pre>';
echo '</pre>';

But it wont connect to my unreal ircd but it will conect to another unreal ircd
sometimes it will connect or try to connect to mine but it wont go to channel #wes
and i can connect to it with a irc client and i got it where you can connect with 5 instances from the same ip PLEASE HELP!!! :evil: :cry: :evil:

Re: php bot cant connect

Posted: Wed Feb 20, 2008 8:11 pm
by Jobe1986
Firstly, you'll need to wait until AFTER you've received numeric 001 before sending the JOIN. Otherwise, if the server gets it before the PONG for the PING cookie, the server will ignore it.

If JOIN is sent too early the server will respond:

Code: Select all 451 JOIN :You have not registered
In this example -> is to the server and <- is from the server

Code: Select all

-> NICK Eboj
<- PING :778B6886
-> USER Eboj localhost * :Eboj
-> PONG :778B6886
<- 001 Eboj :Welcome to the network IRC Network Eboj!Eboj@localhost
-> JOIN #test
On a side note, you're supposed to send NICK before USER.

Also are you aware there is a pre-written PHP class for IRC bots? available on

Re: php bot cant connect

Posted: Fri Feb 22, 2008 4:24 pm
by wescooldude3
I wont to make my own php bot can someone help me with the code for connecting to an irc server? I can do the rest. :shock: :shock:

Re: php bot cant connect

Posted: Sat Feb 23, 2008 1:09 am
by nate
You should look up technical specifications on how connections to an IRC server are meant to be made, step by step per protocol, do that and it won't be hard to understand what you need to do in PHP.

Re: php bot cant connect

Posted: Sat Feb 23, 2008 4:32 pm
by wescooldude3
Where could I learn all about that? :|

Re: php bot cant connect

Posted: Sat Feb 23, 2008 7:36 pm
by Jobe1986