Jump to content

Hi all!


DrLebowski

Recommended Posts

Hi all, I just started with PHP and have started a little project to help me learn (a php irc client)

 

My problem is everything works fine until I try and send data from a different function, I've tried passing the socket as a param, extending the scope of the socket to global etc and nothing seems to work it just tells me that it's not a valid stream. I appreciate any help. Thanks, here's the code.

 

main.php

<?php

require_once('cmds.php');

set_time_limit(0);

if(!isset($_GET['nick'] || !isset($_GET['server'] || !isset($_GET['chan']))
{
	echo "You missed something!";
}
else {

	$addr = $_GET['server'];
	$nick = $_GET['nick'];
	$chan = $_GET['chan'];
	$port = 6667;

	$sock = fsockopen($addr, $port, $errno, $errstr, 5);

	sleep(2); 

	if($sock)
	{
		echo "Registering client: ";
		initRegClient($nick, "127.0.0.1");
		sleep(5);
		joinChan($chan);
		sendMsg($chan ,"Alo! Testing  it works!");
		quit("bye");

	}else {
		echo "Error: ". $errno. " ". $errstr;
	}


}

?>

 

cmds.php

<?php
global $sock;	
function initRegClient($nick, $host)
{
	$regStr = "USER $nick $host $nick :$nick\n\r";
	fputs($sock, $regStr);
}

function nick($nick)
{
	fputs($sock, ":$nick\n\r");
}

function quit($msg)
{
	fputs($sock, "QUIT :$msg\n\r");
	fclose($sock);
}

function part($chan, $msg)
{
	fputs($sock, "PART $chan :$msg\n\r");
}

function joinChan($chan)
{
	fputs($sock, "JOIN $chan\n\r");
}

function sendMsg($chan, $msg)
{
	fputs($sock, "PRIVMSG $chan :$msg\n\r");
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.