0

Hi i am working on a server sent event script to be sent when the user has logged out, but in the network tab the server sent pages are being sent every couple of seconds with no data.

Client-Side script

var source=new EventSource("include/updates.php");

        source.addEventListener('logout',function(event){
            $("#notificationsContainer").append(event.data + "<br />");
            source.close();
        },false);

Server-side script

header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');


if(!isset($_SESSION))
    session_start();

if(!isset($_SESSION['id']))
{
    $time = date('r');
    echo "event: logout\n";
    echo "data: user logged out at {$time}\n\n";
    flush();
}

Thanks for your time,

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by dan_code_guru
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.