phpseclib in a function (multiple)

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

phpseclib in a function (multiple)

Postby H.Murdock » Tue Oct 08, 2013 1:28 am

Hello,

I'm trying to get phpseclib into a function to get multipe informations about multiple machines.

This is my php function:

Code: Select all
<?php
function groesse($ip, $user, $pw){

include('Net/SSH2.php');

$ssh = new Net_SSH2($ip);
if (!$ssh->login($user, $pw)) {
    echo "Login Failed";
}

$ssh->exec('pwd');
$speicher = $ssh->exec('speicher=`df -h` && set -- $speicher && echo "$9"');

echo $speicher;

}
?>


And i am able to call my function once with "<?PHP groesse('192.xx.xx.1', 'admin', 'admin'); ?>" but i have multiple machines i want to check with.

so 1st: <?PHP groesse('192.xx.xx.1', 'admin', 'admin'); ?>
and 2nd: <?PHP groesse('192.xx.xx.2', 'admin', 'admin'); ?>
and so on...

How is that possible? It always just gives me the information for the first one and the next does not show up anyting.
H.Murdock
Traveler
 
Posts: 1
Joined: Tue Oct 08, 2013 1:18 am

Re: phpseclib in a function (multiple)

Postby TerraFrost » Wed Oct 09, 2013 8:14 pm

Sorry for the delay - been busy at work.

Anyway, try taking the include() out of the function and putting it at the beginning of the file. Or do include_once.

Either way it's including Net/SSH2.php multiple times and on the second time you're getting a fatal error because it's trying to create an object that's already been created.
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am


Return to phpseclib support

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron