Mistake:

Warning: Cannot modify header information - it has already been sent (by D: \ OpenServer \ domains \ as \ vendor \ fenom \ fenom \ src \ Fenom \ Template.php (487): eval () 'd code: 7) in D: \ OpenServer \ domains \ as \ app \ classes \ Core.php on line 29

I scanned all the code, looked for problems with include, etc., but did not find a solution. I use PHP7 and I can’t figure it out.

Core.php code:

/** * @param string $page */ static function stop($page = '/') { header('location: '.$page); exit; } 

The file itself in which the error:

 <?php if($Auth->isLoginned()) { Core::stop(); } include INC. 'header.php'; Lang::addWords('registration.ini'); $title = Lang::tr('Registration.title'); if(!empty($_POST)) { $fraction = abs(intval($_POST['fraction'])); Sessions::set('fraction', $fraction); Core::stop('/auth/start/sex'); } $fraction = array(); $fraction = Vars::get('db')->query('SELECT `id`,`name` FROM `fraction` ORDER BY `member` ASC')->fetch_all(); Vars::get('fenom')->display('tutorial/start.tpl', ["fraction" => $fraction]); include INC. 'footer.php'; 

Help me please.

  • 2
    there are such errors when you notice a notice or you print_r before the script sends http headers. Actually, you have the error given the file name and line number, indicating the name of the function that issued something before sending the required headers. Suppose you get an error message, and then you want to make a redirect - it will not work. - teran
  • actually this is what happens to you. in the specified location, someone writes to the output, and then you do the header('location: ...) in Core::stop() - teran
  • I after all received POST data, processed and redirected. It is not right? All thanks figured out. - No0k
  • That's right, the problem is that during the processing, your eval function in the specified template displays something on the screen. After this redirect can not be done. Because in fact, you need to send a 302 response code, and the 200 has already been sent. - teran
  • 2

1 answer 1

The problem was that I brought the header of the site above the receipt of the post request. Children's bug. Final result:

 <?php if($Auth->isLoginned()) { Core::stop(); } if(!empty($_POST)) { $fraction = abs(intval($_POST['fraction'])); Sessions::set('fraction', $fraction); Core::stop('/auth/start/sex'); } Lang::addWords('registration.ini'); $title = Lang::tr('Registration.title'); include INC. 'header.php'; $fraction = array(); $fraction = Vars::get('db')->query('SELECT `id`,`name` FROM `fraction` ORDER BY `member` ASC')->fetch_all(); Vars::get('fenom')->display('tutorial/start.tpl', ["fraction" => $fraction]); include INC. 'footer.php'; 
  • one
    You share the application logic and presentation, and there will never be such problems in principle. - teran
  • Can you roughly explain on the example of this code? I'm just just learning and I will be glad of any information. - No0k
  • read about smarty or twig for example. The bottom line is that in some files there must be a php code (logic / data), in others html (presentation). You seem to have some tpl templates here, but it's not clear. what header.php still connects to. There, I understand you have a site header, but it is not clear why it is also not in tpl templates. - teran