Error Cannot modify header information

StefanS
Posts: 1

Error Cannot modify header information

Hello, how to solve this error ? I read on different sites about this error, but i don't find solve
- Error

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\login\includes\widgets\numar_utilizatori.php:4) in C:\xampp\htdocs\login\succes.php on line 9


succes.php

Code: Select all


<?php 
if 
(isset($_GET['ipc']) && isset($_GET['ipc']) && isset($_GET['pret']) && is_numeric($_GET['u_id']) && is_numeric($_GET['u_id']))
{
    if (!isset($_SESSION["accesari"]))
        $_SESSION['accesari'] = 0;
        $_SESSION['accesari'] = $_SESSION['accesari'] + 1;

    if ($_SESSION['accesari'] > 1) {
        header('Location: cumparare.php');
        exit();
    } else {
.
.
.
?>

numar_utilizatori

Code: Select all

<div class="widget">
   <h2>Utilizatori</h2>
   <div class="inner">
      Momentan sunt <?php echo numar_utilizatori(); ?> utilizatori inregistrati
   </div>
</div>

Admin
Hi,
You can not output something to browser before session_start() or header() function.
So, the php code with those functions must be before html code, or other output with echo, print. Not even a space before <?php.
- The solution is to add html code or other output After session_start() or header() function.
You can store the output (text you want to "echo") into a $variable, then, at the end make echo.

Code: Select all

//all your php code with session_start() and header()
//store you want to echo in some $variable
echo $variable

Adv. Posts: 01

Similar Topics