Content-type not working in PHP

后端 未结 13 2123
时光说笑
时光说笑 2020-12-09 12:16

I have some issues with a PHP file that is not working properly. The Content-type does not get recieved by any browser at all. Firebug interprets the file as text/html inste

相关标签:
13条回答
  • 2020-12-09 12:41

    This is usually caused by a fatal error (ie, syntax error) that causes the script to abort before any of the code is execute (before display_errors can be set through ini_set() at runtime). Try changing display_errors in the php config file (php.ini).

    0 讨论(0)
  • 2020-12-09 12:41

    Looks perfectly ok and the line with the echo should definitely generate a warning. Could it be that you're editing the wrong file?

    0 讨论(0)
  • 2020-12-09 12:42

    the reason is because the header function works only if it is the first one to be called!

    If you put an echo before, the content type automatically becomes text/html

    try to print a CSS code after the header to test if it actually works.

    Read this page for more infos

    EDIT: did you change your post ? :-)

    0 讨论(0)
  • 2020-12-09 12:43

    Check your php.ini file for the output_buffering setting. If it's not set to "off" than PHP is automatically doing output buffering for you. Set that to off and echo something before the header command, and you should see the "classic error".

    You shouldn't use the closing ?>. I know this is a controversial suggestion, but too many times people add a return and/or space after it, which gets output to the browser (before the header). There are very few cases where it not using it would cause a problem.

    0 讨论(0)
  • 2020-12-09 12:45

    Wild guess : open your file with something which would display any BOM. If you see some strange characters before <?php you have your problem. Check your current editor options to save UTF-8 file and make it save them without BOM.

    0 讨论(0)
  • 2020-12-09 12:46
    1. Make sure your file editor doesn't save a BOM in your PHP file.
    2. Try to move error_reporting / ini_set to make them the firsts PHP statements (before header() call). This way you will see all errors (if any). Don't forget to put that OFF in production!
    3. Silly remark, but make sure this file is interpreted as PHP (extension is .php or if not an .htaccess tell the server to interpret as PHP).
    4. Everything else is fine with your code. If it still doesn't work, check your server logs. Maybe something else crashes the execution of this PHP file (invalid MIME or else)...
    0 讨论(0)
提交回复
热议问题