embed problem: "...Cannot modify header information...&

Having trouble installing serendipity?
Post Reply
skylerj
Posts: 4
Joined: Thu Jan 26, 2006 7:34 pm

embed problem: "...Cannot modify header information...&

Post by skylerj »

I've been trying to get this fixed so long, my eyes are about to go crossed, so I'm begging for someone to help me.

First, I'm not a php programmer, but I've installed countless php scripts on my website (phpbb, coppermine, etc), and researched and solved alot of problems, and I've done modifications. I have basic familiarity of php syntax. So that's my experience level.

Basically, I can't get s9y to embed properly on any html page. No matter what, I get variations of this error:

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /home/koopat2/public_html/main/test2.php:5) in /home/koopat2/public_html/seren/index.php on line 18
I've read the offical faq on embedding, but I've tried dozens of things. This is my "by the book" attempt:
I made a wrapper (wrapper.php) which I put in my main webpage directory(main):

Code: Select all

<?php
  ob_start();
  chdir("../seren");
  require("index.php");
  chdir("../main");
  $serendipity_contents = ob_get_contents();
  ob_end_clean();
?>
Seren is my s9y directory.
I made a wrapper with a echo to demonstrate that this part works:
http://www.koopatorivm.com/main/wrapper_echo.php

The problem comes in when I try to call up this code in my main page. For testing purposes, I pair the html down to be very basic.
http://www.koopatorivm.com/main/test2.php
(edit: No works without errors, thanks guys!)

Here's the code I used:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
require("wrapper.php");
echo $serendipity_contents;
?>
</body>
</html>
Like I said, I read the faq. I've probably also read every post on these forums regarding the error, and on google. I get alot of people blaming this error on whitespace, but i tried that solution to death. I wish it was that simple.

Please help, I was really psyched to use this cool weblog. No matter what I try, I can't get it to work.
Last edited by skylerj on Fri Jan 27, 2006 5:56 pm, edited 5 times in total.
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Sigh. I wish I weren't so busy.

I made that page because I wanted to get all the answers from these forums pulled together in one place. I never had time to try it on my own site. I'll bet I've missed something.

I'll look into this for you. I'll install a Serendipity base in a different directory on my website, get it to work embedded, and let you know what else needs to be done. Which version of Serendipity and PHP are you using?
Judebert
---
Website | Wishlist | PayPal
skylerj
Posts: 4
Joined: Thu Jan 26, 2006 7:34 pm

Post by skylerj »

"Powered by Serendipity 0.9.1 and PHP 4.4.1"

I'd really appreciate that judebert, thanks! If it does turn out to be something obvious that I missed, I apologize. But I hammered at it for so long, and for the life of me I couldn't make it work.
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Weird. I just set up 0.9.1 on http://s9y.judebert.com/0_9_1 (hey, why pay $8 a month for web hosting if you can't do weird stuff at a moment's notice?). I created another subdirectory at /embed, to test the directory changing.

Turned out that was necessary, since *.html gets redirected by the .htaccess. That was confusing for a second.

Anyway. I copied your wrapper (as wrapper.php) into my 0_9_1 directory. I copied your test2.php (as skylerj.php and skylerj.html) to my embed directory. I made absolutely no other changes to my Serendipity config (didn't set indexFile to wrapper.php, didn't set config to embedded).

The weird part is: it all worked. Since my .htaccess is set up to parse HTML, you can test either link:
http://s9y.judebert.com/embed/skylerj.html
http://s9y.judebert.com/embed/skylerj.php

Both will give you a themed Serendipity log.

In an attempt to duplicate your error, I configured S9Y embedded. I lost my theming, but kept proper embedding. I set my index file to wrapper.php. Still worked. I copied wrapper.php into the 0_9_1 directory. Still worked.

I got desperate and called 0_9_1/wrapper.php directly from my browser. Blank page. A moment of panic, then... of course not; the wrapper grabs the output into $serendipity_contents, but never prints it out. Duh. Works as expected (or at least, as it should).

So I'm left wondering what's going on. Perhaps our webservers are configured differently. Have you modified your .htaccess in either the /Seren or the /main directory? More likely, you've got a plugin enabled that I don't. Which plugins are you running, both sidebar and event?

A thought just struck me: maybe it is the more mundane "whitespace" explanation. How do you transfer files to your webserver? Do you do the editing on Windows, then transfer in binary mode to a Linux webserver? If so, we could be preserving an extra \n that's being interpreted as a header. If so, make sure that .php, .html, and .htaccess files are always transferred in ASCII mode.

We'll keep plugging at this until we get it. Or you get bored, whichever comes first.
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

The solution is this; the test2.php emits output before the serendipity script is called. This needs to be avoided, as s9y must be the first application to issue content.

Modify test2.php like this:

Code: Select all

<?php
require("wrapper.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
echo $serendipity_contents;
?>
</body>
</html> 
that should work.

BTW, your themes are nice variations, even though a bit too colorful for my personal(!) preference. Wouldn't you like to participate in Serendipity Theming contest? :-)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Nice, clean solution, Garvin. I've added it to the wiki.

I admit to being a little confused, though. Why did it work on my webserver? And check out http://s9y.judebert.com/embed/embed.html -- it DEFINITELY outputs content before Serendipity. In it, Serendipity is themed. So why would it work for me and not skylerj? Something to do with my heroism? :lol:
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Judebert: It can work for you if you enable output buffering, or if you just ignore Warnings in your PHP Config :) With output buffering, you can send header() calls even at the end of your script. :)

Plus, your heroism of course, superJude :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
skylerj
Posts: 4
Joined: Thu Jan 26, 2006 7:34 pm

Post by skylerj »

A million thanks to both judebert (superjude) and garvinhicking. I got it to output without the error message using garvin's solution, as you can see in my "test2" link. As for why it happened in the first place, that is unknown so far.

In answer to judebert, I do have many major modifications in my .htaccess throughout my site. I just tested it with .htaccess turned off and still got the errors.
As for transfering, I use dreamweaver's put/get primarily, and sometimes ws_ftp. I usually edit in dreamweaver and put, but I tested it by writing it in notepad and uploading with ws_ftp, which didn't work. I didn't explicitly make sure it was in ASCII mode, but ws_ftp is usually good at autodetecting that sort of thing, and so is dreamweaver. You are probably right about the server settings though, specifically the php settings that garvin mentioned. My webhost recently made is possible for users to manipulate their php settings from the default configuration in certain ways, so I might also be able to get rid of the errors in that way as well.

As for themes, I'll be doing alot of work and experimentation on the design of my website in the coming weeks, and if I come up with something someone else might like, I'll be sure to post it.

You guys are great though. I really do appreciate your dedication to helping me work this out without making me feel like a impudent newbie.

Thank you x 1000000!
Post Reply