PHP can be downloaded from php. net PHP scripts can be executed from the command line. For additional information and help using PHP, see this PHP manual page.

Server: The domain name of the server used to connect to IRC, such as chat. freenode. net Port: In most cases, this is 6667, but if you’re not sure, check your own IRC client or the network’s website. Nickname: The nickname your bot should use. Keep in mind some special characters are usually not allowed (@#!~). Ident: The ident field appears after the nickname when someone performs a WHOIS like this: nickname!ident@hostname GECOS: This field typically holds a user’s real name or a general description of the bot but you can put whatever you want in there. Channel: You usually want your bot to be present in one or more channels. On most networks, these are prefixed with ‘#’ but it might be something else.

Note that the middle two parameters (in this case, * and 8) must be specified, but they are ignored by the server. Those two are only used between linked servers, not by a directly connecting client.

To do this, we’ll check for server status codes 376 or 422. 376 means the MOTD (message of the day) finished. 422 means there wasn’t any MOTD to send. That MOTD is just something the server sends when you connect, but it is a good indicator for when we can start joining channels. You’ll need to issue a JOIN command. This command can be followed by one or more channels separated by a comma. Notice that the data the server sends is conveniently delimited by spaces. This way we can split the data and reference it using an array index.

Note the offset where messages begin (this applies to both channels and private messages). It is always in the same place. You can handle commands with spaces in them by splicing the chunked data back together ($d). That’s beyond the scope of this article. If the target is a channel (such as #botters-test), then you reply to that. If it’s a private message, this bit will be your bot’s nickname! You must then reply using the sender’s nickname, not yours (otherwise you’d be talking to yourself, and that’s just silly).