Jump to content

Recommended Posts

Hello experts !!!

I have written a php code to make a telnet connection and it works well. But there is only one problem. If I call this php from html page, it requires to enter IP, user name and password every time. I'm expecting to make this program like this. User inputs IP, User Name and Password to HTML form and then it submits to the php and makes the telnet connection. Then the user types the telnet command ( it depends on the device ) to the html text box and pass it to php. Then php will retrieve the out put by passing the command to the remote device. My following code do only half of my expects. I have used "help" command to test.

 

 

<?php

 

if($_POST['action']== 'connect'){

 

$ip = $_POST['ip'];

$user = $_POST['user'];

$pass = $_POST['pass'];

$fp=fsockopen($ip,23);

 

fputs($fp,"$user\r");

sleep(2);

fputs($fp,"$pass\r");

sleep (2);

$sys = fread($fp,8190);

$result = $sys;

fputs($fp,"help\r");

sleep (4);

$sys = fread($fp,8190);

fclose($fp);

$r=array($result,"$",">","#");

$result = str_replace($r,"",$sys);

 

echo ("$result");

exit;

}

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/239517-php-port-opening-help/
Share on other sites

My following code do only half of my expects.

 

You never told us what half it did and what half it didn't do. I am guessing that you do not want to enter your ip, user name, and password every time you want to send a command. The trouble with that is PHP does not remember variables between programs.

 

You might want to look into ajax to do this. Your ip, user name, and password can be set by javascript and you just enter the commands and view results.

 

Use sessions to remember ip, username and password.

 

session_start();

$ip = (isset($_SESSION['ip'])) ? $_SESSION['ip'] : $_POST['ip'];
$user = (isset($_SESSION['user'])) ? $_SESSION['user'] : $_POST['user'];
$pass = (isset($_SESSION['pass'])) ? $_SESSION['pass'] : $_POST['pass'];

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.