*/ include __DIR__ . '/../../initialize.php'; error_reporting( E_ALL ); ini_set( 'display_errors', 1 ); $httpVersion = $_SERVER['SERVER_PROTOCOL'] ?? '1.1'; if ( empty( $_GET['sid'] ) ){ header( "HTTP/{$httpVersion} 400 Mandatory request parameter 'sid' missing" ); exit; } session_id( $_GET['sid'] ); session_start(); session_write_close(); if ( empty( $_SESSION['state'] ) || empty( $_SESSION['auth_url'] ) ){ header( "HTTP/{$httpVersion} 404 Invalid session" ); exit; } $lastSessionData = $_SESSION; header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); header('Access-Control-Allow-Origin: *'); echo ':' . str_repeat( ' ', 2048 ) . "\n"; // 2 kB padding for IE echo "retry: 2000\n"; while ( TRUE ) { if ( connection_aborted() ){ break; } session_start(); session_write_close(); if ( $_SESSION != $lastSessionData ){ echo 'data: ' . json_encode( $_SESSION ) . "\n\n"; $lastSessionData = $_SESSION; } else { echo ": heartbeat\n\n"; } ob_flush(); flush(); sleep( 2 ); } // end of file auth_services/sse.php