Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

93
Views
When does php prepare to send headers?

I wish to review and change headers before they are sent & also be able to stop any content from being send if headers are not to my liking or other conditions are not met.

When I set a function for header_register_callback, the headers can be adjusted perfectly. However, when using a die() statement in the callback, it does not prevent the triggering statement from being outputted. This appears only to be an issue in php 8.0.0 - 8.0.10

Looking at the description of the header register callback: "The callback is executed just after PHP prepares all headers to be sent, and before any other output is sent, creating a window to manipulate the outgoing headers before being sent."

Why does the below example still output:

In php 8.0.0 - 8.0.10, a die statement does prevent the trigger from being outputted: Trigger.

as opposed to:

In php 8.0.0 - 8.0.10, a die statement does prevent the trigger from being outputted:

<?php
    ob_start(); // make sure ob_level is set to 1

    function callback()
    {
        echo "In php 8.0.0 - 8.0.10, a die statement does prevent the trigger from being outputted: ";
        die();
    }
    header_register_callback("callback");

    ob_end_clean();
    echo "Trigger.";
    echo "Execution died before this echo statement.";

I've made a bug report about this as well on: https://bugs.php.net/bug.php?id=81431 Example snippet: https://3v4l.org/0NITj

8 months ago ยท Santiago Trujillo
Answer question
Find remote jobs