10 private static $messageSent =
false;
19 public static function register() {
20 header_register_callback( [ __CLASS__,
'callback' ] );
31 foreach ( headers_list() as
$header ) {
36 $headers[ strtolower( trim(
$header[0] ) ) ][] = trim(
$header[1] );
40 if ( isset( $headers[
'set-cookie'] ) ) {
41 $cacheControl = isset( $headers[
'cache-control'] )
42 ? implode(
', ', $headers[
'cache-control'] )
45 if ( !preg_match(
'/(?:^|,)\s*(?:private|no-cache|no-store)\s*(?:$|,)/i',
48 header(
'Expires: Thu, 01 Jan 1970 00:00:00 GMT' );
49 header(
'Cache-Control: private, max-age=0, s-maxage=0' );
51 'Cookies set on {url} with Cache-Control "{cache-control}"', [
53 'cookies' => $headers[
'set-cookie'],
54 'cache-control' => $cacheControl ?:
'<not set>',
61 self::$headersSentException = new \Exception(
'Headers already sent from this point' );
71 if ( headers_sent() && !self::$messageSent ) {
72 self::$messageSent =
true;
76 $logger->error(
'Warning: headers were already sent from the location below', [
77 'exception' => self::$headersSentException,
78 'detection-trace' =>
new \Exception(
'Detected here' ),