How can I redirect in PHP without header errors?

前端 未结 7 2429
悲哀的现实
悲哀的现实 2021-02-10 07:33

How can I redirect in PHP with this setup below without getting header output errors, I understand that nothing can be printed to the browser before a header is set, I am lookin

7条回答
  •  春和景丽
    2021-02-10 08:14

    You need to buffer the ouput so that the HTTP header is not send on the first output. You can either buffer any ouput implicitly by enabling ouput_buffering or explicitly by calling ob_start. But the latter has to be called before the first output, so ideally in the first line of the script that’s initially called.

提交回复
热议问题