php长轮询中的mysql页面重定向

fnvucqvd  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(247)

在我的一个项目中,我使用php长轮询即时向用户显示数据。我从这里拿到剧本了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();

但什么都没用。为什么这些重定向不起作用。

xfb7svmp

xfb7svmp1#

尝试将php变量更改为以下值。在我看来,设置会话或cookies是用php传输数据最安全的方法。不要将敏感信息放在url字符串中。

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

相关问题