We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

fris on 07/29/08


Tagged

php bot irc sockets


Versions (?)


irc bot with php


Published in: PHP 


  1. <?
  2. // define your variables
  3. $host = "irc.choopa.net";
  4. $port=6667;
  5. $nick="daveyboy";
  6. $ident="dave";
  7. $chan="#usa";
  8. $readbuffer="";
  9. $realname = "davey";
  10.  
  11. // open a socket connection to the IRC server
  12. $fp = fsockopen($host, $port, $erno, $errstr, 30);
  13.  
  14. // print the error if ther eis no connection
  15. if (!$fp) {
  16. echo $errstr." (".$errno.")<br />\n";
  17. } else {
  18. // write data through the socket to join the channel
  19. fwrite($fp, "NICK ".$nick."
  20. ");
  21. fwrite($fp, "USER ".$ident." ".$host." bla :".$realname."
  22. ");
  23. fwrite($fp, "JOIN :".$chan."
  24. ");
  25.  
  26. // write data through the socket to print text to the channel
  27. fwrite($fp, "PRIVMSG ".$chan." :Hello!
  28. ");
  29. fwrite($fp, "PRIVMSG ".$chan." :I am not a bot
  30. ");
  31.  
  32. // loop through each line to look for ping
  33. while (!feof($fp)) {
  34.  
  35. $line = fgets($fp, 128);
  36. echo $line."\n";
  37.  
  38. $line = explode(":ping ", $line);
  39.  
  40. echo $line[0]."\n";
  41.  
  42. if ($line[1]) {
  43.  
  44. fwrite($fp, "PONG ".$line[1]."
  45. ");
  46. }
  47.  
  48. }
  49.  
  50. fclose($fp);
  51. }
  52. ?>

Report this snippet 

You need to login to post a comment.