How to declare more than one header on PHP

后端 未结 9 2267
梦如初夏
梦如初夏 2020-12-11 02:55

I want to send my users to different pages based on user action. So I made multiple functions at the top of the page like so:



        
9条回答
  •  没有蜡笔的小新
    2020-12-11 03:02

    You're getting that error because your script has already produced output (you used echo/print before calling header()). You need to call header() before your script produces any output.

    From the PHP Manual

    http://php.net/manual/en/function.header.php

    Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

    You'll get the following error when you attempt to call header() after sending any output...

    Warning: Cannot modify header information - headers already sent

提交回复
热议问题