- Move header() call to before any includes that might output - Start output buffering at the beginning - Clean output buffer before sending JSON response