ChrisMartino Posted April 20, 2010 Share Posted April 20, 2010 Hey there, I've seen some friends of mine use there bot were when entering a command it will echo the code they put in the chat, i have done the irc bot part of the script but for example if they do !php echo"hello world"; it would return by echoing the result of the code that was ran there, How would i do this?, Thanks in advance, Chris. Link to comment https://forums.phpfreaks.com/topic/199155-run-php-code-within-a-php-script-itself/ Share on other sites More sharing options...
Mchl Posted April 20, 2010 Share Posted April 20, 2010 eval Be careful however. It can run anything, so it's a huge security risk if you do not limit set of allowed commands. Link to comment https://forums.phpfreaks.com/topic/199155-run-php-code-within-a-php-script-itself/#findComment-1045292 Share on other sites More sharing options...
ChrisMartino Posted April 20, 2010 Author Share Posted April 20, 2010 eval Be careful however. It can run anything, so it's a huge security risk if you do not limit set of allowed commands. Thanks, However for some reason it outputs nothing, Heres my IRC bot: <?php // Prevent PHP from stopping the script after 30 sec set_time_limit(0); // Edit these settings $chan = "#Christopher"; $server = "irc.gtanet.com"; $port = 6667; $nick = "ChrisBot"; // 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] == "!php") { eval("\$args = \"$output\";"); fputs($socket, "PRIVMSG ".$channel." :".$output." \n"); } elseif ($rawcmd[1] == "!md5") { fputs($socket, "PRIVMSG ".$channel." :MD5 ".md5($args)."\n"); } elseif ($rawcmd[1] == "!restart") { echo "<meta http-equiv=\"refresh\" content=\"5\">"; } } } } ?> if you use the "!sayit" command with the args variable it outputs this: <~Christopher> !sayit test <ChrisBot> test But when you try !php : <~Christopher> !php echo"test"; <ChrisBot> Link to comment https://forums.phpfreaks.com/topic/199155-run-php-code-within-a-php-script-itself/#findComment-1045296 Share on other sites More sharing options...
ChrisMartino Posted April 20, 2010 Author Share Posted April 20, 2010 Anyone? :[ Link to comment https://forums.phpfreaks.com/topic/199155-run-php-code-within-a-php-script-itself/#findComment-1045325 Share on other sites More sharing options...
Mchl Posted April 20, 2010 Share Posted April 20, 2010 It does probably echo it... somewhere where it runs. Notice how all output of your bot uses fputs to actually send text to irc. So whenever 'echo "something"' is send to your bot, you should strip detect that, and fputs "something" Link to comment https://forums.phpfreaks.com/topic/199155-run-php-code-within-a-php-script-itself/#findComment-1045353 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.