當我嘗試保持ssh2_connect()在session或get中返回的資源ID時,變量的內容消失。我試圖用JavaScript加載它,但它不起作用。我的問題是如何解決這個問題,這裏是我的代碼:保持由ssh2_connect()返回的資源ID php
<?php
session_start();
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
echo $_SESSION['address'];
if(!($con = ssh2_connect($_SESSION['address'], 22))){
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con, $_SESSION['login'], $_SESSION['password'])) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...<br>";
$shell = ssh2_shell($con);
}
}
?>
<head>
<script type="text/javascript">
function display()
{
var v = '<?php echo $shell; ?>';
$('#intro').load('content/test.php?con='+v);
}
</script>
</head>
資源在腳本退出時全部釋放。 – Barmar 2014-09-11 13:24:31