当我尝试保持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