# Cannot modify header information

**URL:** <https://forum.kirupa.com/t/cannot-modify-header-information/65148>\
**Category:** programming\
**Created:** [September 23, 2004, 11:51am UTC](https://forum.kirupa.com/t/cannot-modify-header-information/65148 "2004-09-23T11:51:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ofi](https://avatars.discourse-cdn.com/v4/letter/o/df788c/32.png) [@ofi](https://forum.kirupa.com/u/ofi)\
**Post date:** [September 23, 2004, 11:51am UTC](https://forum.kirupa.com/t/cannot-modify-header-information/65148/1 "2004-09-23T11:51:21Z")

</div>

Hi  
I am setting up guest book, and i got small problem, see link  
[http://www.koddinn.com/prufa/bok/guest\_book.php](http://www.koddinn.com/prufa/bok/guest_book.php)

Code  
[http://www.koddinn.com/prufa/bok/guest\_book.phps](http://www.koddinn.com/prufa/bok/guest_book.phps)

when i hit enter, i get this error  
**Warning** : Cannot modify header information - headers already sent by (output started at /home/koddinn/public\_html/prufa/bok/guest\_book.php:7) in **/home/koddinn/public\_html/prufa/bok/guest\_book.php** on line **66**

**Line 66 [size=2]header(“location: $bodyname”);[/size]**

**[size=2]maybe not big problem, any1 help me**  
**[/size]**

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 23, 2004, 6:16pm UTC](https://forum.kirupa.com/t/cannot-modify-header-information/65148/2 "2004-09-23T18:16:45Z")

</div>

Somewhere in your PHP file some HTML is sent to the browser. When that happens the headers get sent out. And then you try to modify the headers in line 66 but you can’t, because they’re already sent.

It could be something as simple as a blank before your opening PHP tag in the file. Make sure that the very first characters in the script are ‘\<?php’ (without the quotes).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 23, 2004, 8:04pm UTC](https://forum.kirupa.com/t/cannot-modify-header-information/65148/3 "2004-09-23T20:04:38Z")

</div>

Put this at the top of your php page:

ob\_start();

and this at the end:

ob\_end\_flush();

This will clear the output buffer so you can send header data after header data has already been sent.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 23, 2004, 8:13pm UTC](https://forum.kirupa.com/t/cannot-modify-header-information/65148/4 "2004-09-23T20:13:09Z")

</div>

hi  
see this  
[http://www.koddinn.com/prufa/test.php](http://www.koddinn.com/prufa/test.php)

**code**

```php
 
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
	 <title>Title here!</title>
</head>
<body>
<?php
// A Simple PHP Guestbook (runs on flat-files)
// Complete, with simple error checking
$formData = '<form action="#" method="post"><input type="text" name="userName" value="Name"><input type="text" name="userMail" value="Email or URL"><textarea name="userComments">Comments</textarea><button type="submit" name="submit">Submit</button></form>';
if (($userName != "") || ($userName != " ")) { // The only error checking feature included...
$gbFile = fopen("guestbook.txt", "a");
fputs($gbFile, "<b>Name:</b> $userName <br><b>Email/URL:</b> $userMail <br><b>Comments:</b> $userComments <br><hr>");
}
include "guestbook.txt";
print $formData;
?>
</body>
</html>

```

i have got it to work, but i like to have those forms in it, but i mess it up always, **see image**  
can someone help me with this, adding these forms in\*\*.\*\*

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 23, 2004, 8:57pm UTC](https://forum.kirupa.com/t/cannot-modify-header-information/65148/5 "2004-09-23T20:57:58Z")

</div>

value="" is the actual value in the form input area. Just put Name: before the input tag…
