vendredi 20 février 2015

ajax variable not usable in php script


I have written a ajax script that needs to send out soem variables to a php script and then report back a little script to connect with a server. However i can seem to use the store variables i have passed on from my ajax script



<script>
function executeSsh() {
var username = "<?php echo $connect_d["username"] ?>";
var password = "<?php echo $connect_d["password"] ?>";
var ip = "<?php echo $connect_d["dedicatedip"] ?>";
$.ajax({
url: "templates/cloudblok/php/functions.php",
dataType: 'text',
type: "post",
data: {username: username , password: password, ip : ip},
success: function(data){
$('#sshcall').html( data );
},
error: function( jqXhr, textStatus, errorThrown ){
alert( "Request failed: " + textStatus );
}
});

$('.blinstbtn').fadeToggle(1000);
}


So now you can see the three variables who are passed to php as they should and stored as they should in separate variables. However at this point i can't use them any longer and i get a connection error



<?php
include('Net/SSH2.php');


$username = $_POST['username'];
$password = $_POST['password'];
$ip = $_POST['ip'];


echo $username. "<br><br>". $password;


$ssh = new Net_SSH2($ip);
if (!$ssh->login($username, $password)) {
exit('Login Failed');
}

$ssh->read('/.*@.*[$|#]/', NET_SSH2_READ_REGEX);
$ssh->write("uptime\n");
$ssh->setTimeout(10);
$output = $ssh->read('/.*@.*[$|#]|.*[P|p]assword.*/', NET_SSH2_READ_REGEX);

echo "<pre>". $output . "</pre>";

?>


So when i echo out each variable it should the correct value, but when i try to used then further down the script i keep getting the message that login didn't work. I know the script to connect to the server is working as i tested it with just the raw info.


Any idea what i am missing here and how i can solve it. Is there also a way to encrypt the data string that is being send by ajax so now one can pickup the values with something like firebug?


Thanks for the help.





Aucun commentaire:

Enregistrer un commentaire