I want to make a GUI for automation testing tool, currently that was in CLI and we need to convert it ig GUI, now the problem i am facing is that I have selected HTML,CSS,JS for front end and PHP for backend, so can any 1 of u suggest me how to login to the server, which is having some IP? or simply how to login to linux server using PHP code?
5 Answers
You can open a connection via SSH with the "Secure Shell2" PHP module.
https://php.net/manual/en/book.ssh2.php
// open a SSH connection (hostname = IP or network name of the remote computer)
$connection = ssh2_connect('hostname', 22);
// authenticate by login / password
ssh2_auth_password($connection, 'username', 'password');
and then execute a command :
// execute a shell command on the remote computer (eg. 'php -v' to know the PHP version)
$stream = ssh2_exec($connection, 'php -v');
// read the result from the remote computer to your local computer
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
// print the result in your local computer
echo stream_get_contents($stream_out);
10 Comments
With PHP you can't log into a Server as you only run a php-script but you're not acctually a user that does stuff. That said there is a user set up for php-scripts. Everytime you send a request to get a php-file that user runs the script and sends beck the result.
If you want to output data from your server you have to have these data accessible via php. Than you can open those PHP-files as part of a website.
Comments
You don't login to the server from PHP, however if your web server is running on the same server you are trying to control, you can easily execute shell commands and scripts from PHP. shell_exec
Be careful of the the permission you are granting your commands and scripts.
any 1 of u: Please use English!