PHP Telnet by Gecko Tribe
PHP Telnet by Gecko Tribe
facebook youtube twitter linkedin google-plus

PHP Telnet

Run telnet sessions from PHP scripts

Requirements | Download | Security | Usage Examples


Requirements:

PHP Telnet requires PHP version 4.3 or higher, with support for fsockopen enabled.

Download:

X

Free Download



Privacy Guarantee: I will never share your email address with anyone, and you can unsubscribe at any time.

Security:

I strongly recommend that you do not store your username and password in any PHP script unless only people you trust completely have access to your server. Instead, use a form to enter the username and password each time the script is run. Exercise caution with any system that transmits passwords over unencrypted connections.

Usage Examples:

Basic usage

NOTE: With PHP Telnet versions before 1.1, the following code will not display error messages for certain types of connection failures. If you are using an older version, either upgrade to the current version or use the next code example.

<?php
require_once "PHPTelnet.php";

$telnet = new PHPTelnet();

// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1
$result = $telnet->Connect('www.somewhere.com','login name','password');

if ($result == 0) {
$telnet->DoCommand('enter command here', $result);
// NOTE: $result may contain newlines
echo $result;
$telnet->DoCommand('another command', $result);
echo $result;
// say Disconnect(0); to break the connection without explicitly logging out
$telnet->Disconnect();
}
?>

Display your own error messages

NOTE: With PHP Telnet versions before 1.1, the show_connect_error option was not supported. If you are using an older version, either upgrade to the current version, or delete the line that sets show_connect_error.

<?php
require_once "PHPTelnet.php";

$telnet = new PHPTelnet();
$telnet->show_connect_error=0;

// if the first argument to Connect is blank,
// PHPTelnet will connect to the local host via 127.0.0.1
$result = $telnet->Connect('www.somewhere.com','login name','password');

switch ($result) {
case 0:
$telnet->DoCommand('enter command here', $result);
// NOTE: $result may contain newlines
echo $result;
$telnet->DoCommand('another command', $result);
echo $result;
// say Disconnect(0); to break the connection without explicitly logging out
$telnet->Disconnect();
break;
case 1:
echo '[PHP Telnet] Connect failed: Unable to open network connection';
break;
case 2:
echo '[PHP Telnet] Connect failed: Unknown host';
break;
case 3:
echo '[PHP Telnet] Connect failed: Login failed';
break;
case 4:
echo '[PHP Telnet] Connect failed: Your PHP version does not support PHP Telnet';
break;
}
?>