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,

Any pointers as to what it is?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.