I am using php-long-polling to display data to user on instant basis in one of my projects. I got the script from here https://github.com/panique/php-long-polling When counter sets to 1 it has to redirect to some other page. This redirection is not happening in server.php script.
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>";
}
}
}
I tried
header("location:result.php?id=$id");
exit();
But nothing did work. why these redirection not working.
Try to change your PHP variable to this. Setting sessions or cookies is in my opinion is the most secure way to transfer data with PHP. Don't put sensitive info in a URL string.
header("location:result.php?id=".$id."");
exit();