Is it possible to open a socket with one function and send commands to that socket with another function all from the same page ?
When I try this I get: Warning: fputs(): supplied argument is not a valid stream resource
This is the code I'm using
connect();
cmd("cd /home/tom\n ls\n");
close();
function connect () {
global $passwd;
if (!$fp = @fsockopen("127.0.0.1", 23, $errno, $errstr, 5)) {
exit('Login Failed');
}
stream_set_timeout($fp, 1);
fputs($fp, "tom\n"); sleep(1);
fputs($fp, "$passwd\n"); sleep(1);
$res = fread($fp,1024);
var_dump($res);
}
function cmd ($cmd) {
global $fp;
fputs($fp, $cmd); sleep(1);
$res = fread($fp,1024);
var_dump($res);
}
function close () {
global $fp;
fclose($fp);
}
Any idea how to get this to work ? Thanks