shankcode Posted June 16, 2011 Share Posted June 16, 2011 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/239517-php-port-opening-help/ Share on other sites More sharing options...
sunfighter Posted June 16, 2011 Share Posted June 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/239517-php-port-opening-help/#findComment-1230652 Share on other sites More sharing options...
redixx Posted June 16, 2011 Share Posted June 16, 2011 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']; Quote Link to comment https://forums.phpfreaks.com/topic/239517-php-port-opening-help/#findComment-1230660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.