【发布时间】:2011-07-30 01:22:21
【问题描述】:
我想在我的页面上有一个类似彗星的 iframe,但是当会话更改 iframe 中的信息时 not 并且我在 iframe 中转储了 $_SESSION 变量和它没有改变。
我的问题是,当客户端$_SESSION 发生变化时,如何更新comet iframe 中的$_SESSION 变量?
非常感谢^_^
用代码更新:
客户:
<?php
session_start();
if(!isset($_SESSION['count'])) $_SESSION['count'] = 0;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Comet</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='../js/jquery.js'></script>
<script type="text/javascript">
function test_function(msg){
$('p').html(msg)
}
$('div').click(clickMe);
function clickMe(event){
$.ajax({
url: 'addSess.php'
})
}
</script>
</head>
<body>
<p>This is a test</p>
<div>click me</div>
<iframe src="output.php" width="0" height="0" style="display: none;"></iframe>
</body>
</html>
彗星 iframe (output.php):
<?php
session_start();
ob_start();
echo 'hello';
flush_buffers();
while(true){
echo "<script>window.parent.test_function('".time().' session: '.$_SESSION['count']."');</script>";
flush_buffers();
sleep(1);
}
function flush_buffers(){
ob_end_flush();
ob_flush();
flush();
ob_start();
}
?>
addSess.php:
<?php
session_start();
if(!isset($_SESSION['count'])) $_SESSION['count'] = 0;
$_SESSION['count']++;
echo $_SESSION['count'];
?>
我注意到的另一件事是它冻结了浏览器无法访问我的网站,一旦我关闭客户端,其他所有内容都会加载
【问题讨论】: