Skip to content
Advertisement

PuTTY shows weird characters when connected to Telnet/sockets server implemented in PHP

I am working on a PHP program that implements a sockets and Telnet server. I am using PuTTY as my Telnet client. My problem is that whenever I type something in PuTTY, it shows me these weird characters before what I actually typed:

I reinstalled PuTTY but it did not work.

This is my PHP server code:

$sock_server = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_bind($sock_server, '127.0.0.1', 9000);
$result = socket_listen($sock_server, 1);
$sock_cli = socket_accept($sock_server);

$msg = "Insert Password: ";
socket_write($sock_cli, $msg, strlen($msg));

$pass = socket_read ($sock_cli, 2048, PHP_NORMAL_READ);
echo $pass;
if ($pass != "1234"){
    echo $pass;
    exit;
}

Any help to solve my problem is appreciated. Thanks.

Advertisement

Answer

I do not see any Telnet code in your example. You are using raw sockets. So you need to use Raw connection type in PuTTY to match that.

If you select Telnet connection type in PuTTY, PuTTY will send you Telnet control sequences. You read and process those sequences as if they were plain text input.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement