Support Forums

Full Version: Connect IRC using php on linux systems
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello SF Victoire

This script is created to be used for connecting to IRC clients using PHP on a linux system.

PHP Code:
<?
function phpbot($server$port$user$nick$realname$channel) {
  
$sockname fsockopen($server$port$errno$errstr) or exit("$errno $errstr");
  
$repeat "0";
  while (
$sockread fgets($sockname512)) {
    
$sockread explode(" "$sockread);
    if (!
$repeat) {
      
fputs($sockname"USER $user x x :$realname\n");
      
fputs($sockname"NICK $nick\n");
    }
    if (
$sockread[0] == "PING") {
      
fputs($sockname"PONG :$sockread[1]\n");
    }
    if (
$sockread[1] == "001") {
      
fputs($sockname"JOIN $channel\n");
    }
    if (
fnmatch("43?"$sockread[1])) {
      
fputs($sockname"NICK $nick".str_repeat(mt_rand(09), 3)."\n");
    }
    
$repeat++;
  }
}
?>
<html>
<center>
<input type="button" onclick="<?=phpbot("irc.kingskrown.com","6667","phpbot","phpbot","phpbot","#kingskrown");?>" value="Connect"/>
</center>
</html> 

That's it Smile Enjoy
Hey man thanks I've been looking for ways to do this, this is helpful!
Did you write this?
(10-13-2009, 02:29 AM)NinjaGeek Wrote: [ -> ]Hey man thanks I've been looking for ways to do this, this is helpful!

Thankyou Ninja Yeye
I'm posting what i'm using for windows for connecting IRC using php :
PHP Code:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<
style type="text/css">html{background:#000;color:#0F0;font:Verdana, Geneva, sans-serif;font-size:12px;}</style>
</head>
<
body>
<?
php
    
//Configuration
    
$nick "Spl3enBot";
    
$user "Spl3en";
    
$channel "#whatever";
    
$server "irc.server.net";

    
//Begin of the script
    
$socket socket_create(AF_INETSOCK_STREAMSOL_TCP);
    
$result socket_connect($socketgethostbyname($server), 6667);
    
$in "NICK ".$nick."\r\n";
    
$in .= "USER  ".$user." 8 *  : ".$user."\r\n";
    
$in .= "USERHOST Userhost\r\n";
    
$in .= "JOIN :".$server."\r\n";
    
socket_write($socket$instrlen($in));
    while (
$out socket_read($socket1024)){
        if (
preg_match("/PING/i",$out)) socket_write($socket,"PONG ",strlen("PONG "));
        echo 
"<font color=blue>Socket_read = <i>".$out."</i></font><br>";
    }
    
socket_close($socket);
?>
</body></html> 

Hope it helps Smile
(10-13-2009, 06:12 PM)Spl3en Wrote: [ -> ]I'm posting what i'm using for windows for connecting IRC using php :
PHP Code:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<
style type="text/css">html{background:#000;color:#0F0;font:Verdana, Geneva, sans-serif;font-size:12px;}</style>
</head>
<
body>
<?
php
    
//Configuration
    
$nick "Spl3enBot";
    
$user "Spl3en";
    
$channel "#whatever";
    
$server "irc.server.net";

    
//Begin of the script
    
$socket socket_create(AF_INETSOCK_STREAMSOL_TCP);
    
$result socket_connect($socketgethostbyname($server), 6667);
    
$in "NICK ".$nick."\r\n";
    
$in .= "USER  ".$user." 8 *  : ".$user."\r\n";
    
$in .= "USERHOST Userhost\r\n";
    
$in .= "JOIN :".$server."\r\n";
    
socket_write($socket$instrlen($in));
    while (
$out socket_read($socket1024)){
        if (
preg_match("/PING/i",$out)) socket_write($socket,"PONG ",strlen("PONG "));
        echo 
"<font color=blue>Socket_read = <i>".$out."</i></font><br>";
    }
    
socket_close($socket);
?>
</body></html> 

Hope it helps Smile

I think thats very good. Thanks spleen
Check out PHP-iRC
(10-20-2009, 09:44 PM)iintens Wrote: [ -> ]Check out PHP-iRC

hmm , whats that, any link will be appreciated Smile
(10-23-2009, 10:23 AM)Codine Wrote: [ -> ]http://www.phpbots.org/

Thanks, I will take a leap to this.
You're welcome, i think that's the site your looking for, if not then i'll have another look for you.
Pages: 1 2