Set variable from dropdown menu

I am using the below to sent ssh commands through a web interface. For example, to get the hostname of a Linux computer:

index.html

[code]

Select Client
Client001
Client002
Client003

[/code]

hostname.php
[php]<?php
include(‘Net/SSH2.php’);
include(‘variables.php’);

$ip = $_GET[‘clients’];
$ssh = new Net_SSH2(’$ip’);
if (!$ssh->login($user, $pass)) {exit(‘Login Failed’);}
echo $ssh->exec(‘hostname’);
?>[/php]

In hostname.php if I set the $ip variable manually, everything works as expected. But when I use
[php]$ip = $_GET[‘clients’];[/php]
I get a message saying “Login Failed”

When I echo $ip I correctly get the IP Address of the dropdown selection.

What I’m I doing wrong here?

Thanks

This fixed it

[code]<?php
include(‘Net/SSH2.php’);
include(‘variables.php’);

$ip = $_GET[‘clients’];
$ssh = new Net_SSH2($ip);
if (!$ssh->login($user, $pass)) {exit(‘Login Failed’);}
echo $ssh->exec(‘hostname’);
?>[/code]

You really should be using post instead of get when using a form, for it’s a little more secure. I would also do this

<option value="">Select Client</option>

instead of this

<option value="SelectClient">Select Client</option>

that way you could do

[php]if (isset($_POST[‘clients’]) && $_POST[‘clients’] != “”) { // or … && !empty($_POST[‘clients’]) ) …
$ip = $_POST[‘clients’];
}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service