How can I redirect in PHP without header errors?

前端 未结 7 2135
旧时难觅i
旧时难觅i 2021-02-10 08:04

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:31

    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.

提交回复
热议问题