How to declare more than one header on PHP

后端 未结 9 2232
梦如初夏
梦如初夏 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:27

    Here is how i like to do when i need to send multiple headers :

    $headers = array(
       'Location' => 'http://www.stackoverflow.com',
       'Content-Type' => ' application/pdf',
    );
    
    foreach ($headers as $headerType => $headerValue)
    {
       header($headerType . ': ' . $headerValue);
    }
    

    Use headers_sent() to check if you'll be able to send headers or not.

提交回复
热议问题