Author Topic: Simple PHP scripts  (Read 332 times)

Jane

  • Management
  • Full
  • *******
  • Posts: 130
  • Reputation +1/-0
  • mIRC Scripters
    • View Profile
Simple PHP scripts
« on: February 08, 2011, 05:41:54 pm »
 a basic IRC Bot with a few commands.

Commands are:

!sayit <Your message here> - The bot just repeats your message.
!md5 <your message here> - The bot just says the md5 sum of your message.

How to run it, you change the variables to which i said to edit. then you save it as whatever you want.php then just double click it on windows, or on linux type php filename.php...

you must have php installed.


Code: [Select]
?php
// Prevent PHP from stopping the script after 30 sec
set_time_limit(0);
 
// Edit these settings
$chan = "#php";
$server = "127.0.0.1";
$port = 6667;
$nick = "PHP_Bot";
 
// STOP EDITTING NOW.
$socket = fsockopen("$server", $port);
fputs($socket,"USER $nick $nick $nick $nick :$nick\n");
fputs($socket,"NICK $nick\n");
fputs($socket,"JOIN ".$chan."\n");
 
while(1) {
while($data = fgets($socket)) {
        echo nl2br($data);
        flush();
 
        $ex = explode(' ', $data);
$rawcmd = explode(':', $ex[3]);
$oneword = explode('<br>', $rawcmd);
        $channel = $ex[2];
$nicka = explode('@', $ex[0]);
$nickb = explode('!', $nicka[0]);
$nickc = explode(':', $nickb[0]);
 
$host = $nicka[1];
$nick = $nickc[1];
        if($ex[0] == "PING"){
        fputs($socket, "PONG ".$ex[1]."\n");
        }
 
$args = NULL; for ($i = 4; $i < count($ex); $i++) { $args .= $ex[$i] . ' '; }
 
        if ($rawcmd[1] == "!sayit") {
        fputs($socket, "PRIVMSG ".$channel." :".$args." \n");
        }
elseif ($rawcmd[1] == "!md5") {
fputs($socket, "PRIVMSG ".$channel." :MD5 ".md5($args)."\n");
}
}
}
?>

Share on Bluesky Share on Facebook


CJ101

  • PAWN Expert
  • Global Moderator
  • Newbie
  • ****
  • Posts: 39
  • Reputation +1/-0
  • SA-MP Ftw
    • View Profile
    • PS3GamingWorld
Re: Simple PHP scripts
« Reply #1 on: February 08, 2011, 07:06:11 pm »
hm... i decided to use this, i moved the file (bot.php) into my webserver (has php5 i think).. but when i go to the file, it does nothing but show the code. :/

King_Hual

  • Trial Moderator
  • Newbie
  • ***
  • Posts: 36
  • Reputation +3/-2
    • View Profile
Re: Simple PHP scripts
« Reply #2 on: February 08, 2011, 07:16:53 pm »
It can only be used with cmd.exe on Windows, and something else on another OS - Linux but i don't know about that. I don't think you can use it from your webhost :p