In the case of making a connection using PHP fsockopen used a command that allows you to open a socket on the specified server and port, in addition to running the script is certainly no specific requirement that the server you use must support PHP scripts, then allow you to use the fsockopen command. : Next create a new file named form.html and place the code below:
===
==
==
Next paste the following code into a file irc.lib.php:
PHP Code: PHP Code:
==
set_time_limit(0);
define('CRLF',"\r\n");
$nick = $_POST['nick'];
$user = $_POST['user'];
$localhost = ‘127.0.0.1';
$server = $_POST['server'];
$port = $_POST['port'];
$nama = $_POST['nama'];
$channel = $_POST['channel'];
$fp = fsockopen($server,$port, &$err_num, &$err_msg, 30);
if(!$fp) {
echo "Maaf, tidak bisa menghubungi server $server";
exit;
}
$data = 'NICK ' . $nick . CRLF;
$data .= 'USER ' . $user . ' ' . $localhost . ' ' . $server . ' :' . $nama . CRLF;
fputs($fp, $data);
$response = '';
while (!feof($fp)) {
$response .= fgets($fp, 1024);
while (substr_count($response,CRLF) != 0) {
$offset = strpos($response, CRLF);
$data = substr($response,0,$offset);
$response = substr($response,$offset+2);
if ( substr($data,0,1) == ':' ) {
$offsetA = strpos($data, ' ');
$dFrom = substr($data,1,$offsetA-1);
$offsetB = strpos($data, ' :');
$dCommand = substr($data,$offsetA+1,$offsetB-$offsetA-1);
$dText = substr($data,$offsetB+2);
if (substr($dCommand,0,3) == '004' ) {
fputs($fp,'JOIN ' . $channel . CRLF);
}
elseif ( substr($dCommand,0,7) == 'PRIVMSG' ) {
if ( Ord(substr($dText,0,1)) == 1 ) {
if ( substr($dText,1,4) == 'PING' ) {
fputs($fp,':' . $nick . ' NOTICE ' . $dFrom . ' :' .
chr(1) . 'PING ' . substr($dText,6) . chr(1) . CRLF);
}
elseif ( substr($dText,1,7) == 'VERSION' ) {
fputs($fp,':' . $nick . ' NOTICE ' . $dFrom . ' :' .
chr(1) . 'VERSION PHPirc' . chr(1) . CRLF);
}
}
else {
fputs($fp,$dText . CRLF);
}
}
}
elseif ( substr($data,0,4) == 'PING' ) {
fputs($fp,'PONG . substr($data,5) . CRLF);
}
}
}
fclose ($fp);
?>
==
After the above two files created are now open your browser and navigate to the file form.html, for example http://www.domain.com/irc/form.html and fill your identity specification. Now you can see the nick that you fill in the join the channel you specify. . Actually the script above is the beginning of your learning to make a bot on IRC. Please attempting.
The authors suggest that you try this script only on a free hosting server only, because it feared if you use a hosting server that you buy, then your account can be removed unilaterally by the management server.
No comments:
Post a Comment