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,

Recommended Answers

@dan_code_guru

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.

You are missing something from your php code! Read …

Jump to Post

All 2 Replies

Any pointers as to what it is?

Be a part of the DaniWeb community

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