【问题标题】:page redirection in php long pollingphp长轮询中的页面重定向
【发布时间】: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


【解决方案1】:

尝试将您的 PHP 变量更改为此。在我看来,设置会话或 cookie 是使用 PHP 传输数据的最安全方式。不要将敏感信息放在 URL 字符串中。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-07
    • 2014-04-21
    • 1970-01-01
    • 1970-01-01
    • 2013-11-18
    • 2011-02-06
    • 1970-01-01
    • 2022-01-19
    相关资源
    最近更新 更多