Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Wendell Pulsipher](https://uploads.teamtreehouse.com/production/profile-photos/115958/micro_Intellus.jpg)
Wendell Pulsipher
10,183 PointsPHP header problems
I have seen these errors before but I guess I just never fully understood how to fix them:
Warning: Cannot modify header information - headers already sent by (output started at /path/to/file/history.php:26) in /path/to/file/header.php on line 5
This is my code in history.php on line 26:
<?php include('inc/header.php'); ?>
and this is the code on lines 1-5 of header.php:
<?php
if(isset($_COOKIE['cookiename'])){
$logged = true;
$username=$_COOKIE['cookiename'];
setcookie('cookiename',$username,time()+60*30,'/',"","",true);
how do I get rid of this error?
5 Answers
![chrisp](https://uploads.teamtreehouse.com/production/profile-photos/1288712/micro_cp.png)
chrisp
13,686 PointsI see. Looking at it again. I think you set this on line 26?
it looks like the cookies are sent in the HTTP response header, and the html content already started and it cannot go back and add the cookies.
My last attempt would be to move your include header all the way on Line 1, before any HTML tags, and below the doctype. Where the set cookies( ) are all the way on top. That way the cookies can be set before any outputs. I can't see all your codes but that my last solution. Good luck.
![chrisp](https://uploads.teamtreehouse.com/production/profile-photos/1288712/micro_cp.png)
chrisp
13,686 PointsInstead of using include( ), maybe try using
require_once('inc/header.php'); Hope that can fix it.
![Wendell Pulsipher](https://uploads.teamtreehouse.com/production/profile-photos/115958/micro_Intellus.jpg)
Wendell Pulsipher
10,183 Pointsthanks, but I have tried that already... didn't work. Randy Hoyt , Hampton Paulk , any suggestions?
![Jason Anello](https://secure.gravatar.com/avatar/d1304e75238ff7f216f55adc03e08ea1?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jason Anello
Courses Plus Student 94,610 PointsHi Wendell,
Can you post the first 26 lines of that file?
Do you have any blank lines in your php files before the opening php block?
You want to make sure that nothing is being output to the page before setcookie
![Wendell Pulsipher](https://uploads.teamtreehouse.com/production/profile-photos/115958/micro_Intellus.jpg)
Wendell Pulsipher
10,183 PointsOh good heavens I see the problem. Chris P while having html before the include, so I just took that out of the header file and let all the cookies be set at the beginning of the history.php and shabam! problem solved. I forgot that html counts as output
![chrisp](https://uploads.teamtreehouse.com/production/profile-photos/1288712/micro_cp.png)
chrisp
13,686 PointsYay, I am Glad you solved it.