Search code examples
phpnginxmamp

Why PHP header() is not working?


<?php
    header('Content-type: application/xml');
    echo "test";
?>

I use this code and its not working in MAMP and the response headers are:

Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=UTF-8
Date:Wed, 15 Mar 2017 15:12:45 GMT
Server:nginx/1.11.4
Transfer-Encoding:chunked
X-Powered-By:PHP/7.1.1

Solution

  • Try this instead:

    <?php
        header('Content-type: application/xml');
        echo "<example>hello, world!</example>";
    

    Gives you:

    Connection:Keep-Alive
    Content-Type:application/xml
    Date:Wed, 15 Mar 2017 15:12:45 GMT
    Server:nginx/1.11.4
    Transfer-Encoding:chunked
    X-Powered-By:PHP/7.1.1
    

    Links: