i have a piece of code which asks the user for a command and then makes a ssh connection to the server and outputs the result. the problem is if the user inputs the command cd /etc he navigates to that directory but if he then enters the command pwd the output is /root which means it closed the first connection and it started a new connection.
<?php
$ip= $_SESSION['ip'];
$user=$_SESSION['user'];
$pass=$_SESSION['pass'];
$connection = ssh2_connect($ip);
ssh2_auth_password($connection,$user,$pass);
if(isset($_POST['but_submit'])){
$input=$_POST['input'];
$stream = ssh2_exec($connection,$input);
$err_stream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
stream_set_blocking($stream,true);
stream_set_blocking($err_stream, true);
$output= stream_get_contents($stream);
$result_err = stream_get_contents($err_stream);
echo "<fieldset><pre>$output$result_err</pre></fieldset>";
}else{echo 'Vendos nje komande';}
?>