php 长轮询中的页面重定向

page redirection in php long polling

我正在使用 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 变量更改为此。在我看来,设置会话或 cookie 是使用 PHP 传输数据的最安全方式。不要将敏感信息放在 URL 字符串中。

header("location:result.php?id=".$id."");
exit();