I'm trying to create something like this :
telnet towel.blinkenlights.nl 666
which you have to write in terminal & it send you some response and user can also send input if server asks.
I've searched alot for it but didn't get enough. Just this little code :
<?php
$IP_ADDR='127.0.0.1';
$PORT='80';
echo "Welcome to LOCALHOST...";
$connection = fsockopen($IP_ADDR, $PORT);
if(!$connection){
echo "No Connection";
}else{
echo "Hello, what's your name?";
}
?>
But the output shows something like this :
telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
So after connected with localhost it's not showing the output, I've to type any char then press enter then it shows this output :
g
Welcome to LOCALHOST...Hello, what's your name?Connection closed by foreign host.
So how can I avoid this everytime inserting char for output?
Please help me. Thanks
Edited Code :
My Code :
$IP_ADDR='127.0.0.1';
$PORT='80';
$connection = fsockopen($IP_ADDR, $PORT);
if(!$connection){
echo "No Connection";
}else{
$filename = "sampledata.txt";
$somecontent = "Weekend is about to come.";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file";
exit;
}
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file";
exit;
}
echo "Success";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
}
Output :
telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
d
Success, wrote (Weekend is about to come.) to file (sampledata.txt)Connection closed by foreign host.