Error with header (location) [duplicate]

0

I have the following code

<?php                         
    if(!$_GET){
      header('Location:blog.php?pagina=1');
    }                            
  ?>

and it gives me the following error:

  

Warning: Can not modify header information - headers already sent by   (output started at C: \ xampp \ htdocs \ gp \ includes \ header2.php: 1) in   C: \ xampp \ htdocs \ gp \ blog.php on line 108

and in the header2.php file I have the following code

<header class="header-two">
    <div class="topbar-area topbar-area-2 fix hidden-xs">
        <div class="container">
            ...
         </div>
    </div>
</header>
    
asked by Luis Hernandez 11.08.2018 в 03:28
source

1 answer

1

Try using buffer

<?php
  ob_start();
     if(!$_GET){
        header('Location:blog.php?pagina=1');
     }    
  ob_end_flush();
?>

This is assuming that your php script consists of nothing more than what you placed

    
answered by 11.08.2018 в 03:52