Can not modify header? [duplicate]

2

How can I solve this ?, I went up my website for the first time and I get the following error messages when viewing the site. Of course, this error is not represented locally, so I will be omitting some important rule perhaps when uploading it to some domain ...

    !DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
            <?php
            include 'config.inc.php';
            $db=new Conect_MySql();
                $sql = "select*from book where id=".$_GET['id'];
                $query = $db->execute($sql);
                if($datos=$db->fetch_row($query)){
                    if($datos['file']==""){?>
            <p>NO tiene archivos</p>
                    <?php }else{
   header('Content-type: application/pdf');
                        readfile('archivos/'.$datos['file']);
                    }
                } 
            ?>
        </body>
    </html>
    
asked by KJSK 07.12.2018 в 00:05
source

1 answer

1

What is happening to you is that you send a header after to print something on screen, and that is not allowed (basically speaking).

What you have to do is this:

<?php
header('Content-type: application/pdf');
?>
<!DOCTYPE html>
<html>
...

That is, the sending of headers should be always before "anything" that can be printed on the screen. This, for example, would also give you the same error:

<?php
echo 'hola';
header('Content-type: application/pdf');
...
    
answered by 07.12.2018 / 00:44
source