DrLebowski Posted July 16, 2007 Share Posted July 16, 2007 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"); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.