How to declare more than one header on PHP

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

    Try something like this:

    <?php
    
    $page = // use an if statement or whatever you need to figure out 
            //which page you need (pagea.php, etc.)
    
    fnx($page)
    
    function fnx($page) {
        header("location: " . $page);
    }
    
    ?>
    

    or

    <?php
    
    $page = // use an if statement or whatever you need to figure out 
            //which page you need (pagea.php, etc.)
    
    header("location: " . $page);
    
    ?>
    
    0 讨论(0)
  • 2020-12-11 03:25
    function one() {
         return "location: pagea.php";
    }
    function two() {
         return "location: pageb.php";
    }
    function three() {
         return "location: pagec.php";
    }
    
    header(one()); // for example
    

    Maybe something like that?

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题