So, I am working on this site and for some reason I can not figure this out. I keep getting the error

Warning: Cannot modify header information - headers already sent by (output started at /home/site/public_html/header.php:42) in /home/site/public_html/index.php on line 68

I have checked everything and maybe I need new pair of eyes

Here is the header

include "config.php";

include 'functions.php';

$session_username = $_SESSION['username'];
$session_uid = $_SESSION['uid'];

$view = mysql_query("SELECT * FROM num");
$views = mysql_num_rows($view);

$views = $views;

$time = date("H:i:s");
$date = date("Y-m-d");
$browser = $_SERVER['HTTP_USER_AGENT'];
$firefox = strpos($browser, 'Firefox') ? true : false; // All Firefox
$chrome = strpos($browser, 'Chrome') ? true : false; // All chrome
$internetexplorer = strpos($browser, 'IE') ? true : false; // All chrome
    if ($firefox){
        $browser = 'Firefox';
    }else if ($chrome){
        $browser = 'Chrome';
    }else if ($internetexplorer){
        $browser = 'Internet Explorer';
mysql_query("UPDATE activity SET last_page_view = '$PHP_SELF', browser = '$browser', time = '$time', date = '$date' WHERE user_id = $session_uid");


<!doctype html>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<META name="keywords" content="" />
<META name="description" content="">
<link rel="stylesheet" href="main.css" />
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-25371046-6']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

<div id="wrapper">
<div id="head_container">
<div id="header"><a href="index.php" alt="logo"><img src="logo.png" alt="logo" style="margin-left: 26px; margin-top: 6px;"></a>
<div id="stats">
<div id="counter">
<div style="width: 200px; text-align: center; font-family: arial; font-size: 12px;">Total Delievered<br />
<b><?php echo number_format($num); ?></b>
<div id="content">

I am thinking it has to be something simple I am missing .. Any help would be greatly appreciated

Recommended Answers

All 4 Replies


Try with adding this line after the session_start

ob_start();  // line for preventing header has already been sent error...

and this line in your footer

ob_end_flush();  // line for preventing header has already been sent error...keep this line last

before the </body> tag

Hopefully this should do the trick


I am not getting the error.

Created 2 pages functions.php, and index.php. I just get what i would expect, as it cannot execute the SQL

Did you have white space in your orig code?

ob_end_flush(); // line for preventing header has already been sent error...keep this line last

That acctually fixed it.. Though I am curious as to why it fixed it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.