【发布时间】:2018-01-12 03:56:10
【问题描述】:
我正在使用 php-long-polling 在我的一个项目中即时向用户显示数据。我从这里得到了脚本https://github.com/panique/php-long-polling 当计数器设置为 1 时,它必须重定向到其他页面。 server.php 脚本中没有发生这种重定向。
ob_start();
set_time_limit(0);
include('includes/sessions.php');
while (true) {
$last_ajax_call = isset($_GET['timestamp']) ? (int)$_GET['timestamp'] : null;
$id = $_GET['id'];
$sql = "SELECT max(gid) FROM grp WHERE gid=".$id."";
$result = mysqli_query($con, $sql);
if ($last_ajax_call == null || $last_change_in_data_file > $last_ajax_call) {
$sql = "SELECT is_set, start FROM grp WHERE gid =".$id."";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
if(($row['is_set'] == 1) && ($row['start'] == 1))
{
//Here redirection should happen
$data .= "<script> window.location.href = './result.php?id=".$id."</script>";
}
}
}
我试过了
header("location:result.php?id=$id");
exit();
但没有任何效果。 为什么这些重定向不起作用。
【问题讨论】:
-
请提供完整代码
标签: php mysql redirect long-polling