当我尝试保留ssh2_connect()在session或get中返回的ressource id时,变量的内容为dissapear。我试图用JavaScript加载它但它不起作用。我的问题是如何在这里解决这个问题是我的代码:
<?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>
答案 0 :(得分:0)
你不能这样做。当脚本退出时,其所有网络连接和文件流都将关闭。资源无法从一个脚本调用传递到另一个脚本调用,因此将它们保存在会话,cookie中是没有意义的