include PHP header/footer for wrapping

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

Post Reply
wretch
Posts: 8
Joined: Wed Jun 28, 2006 4:07 pm

include PHP header/footer for wrapping

Post by wretch »

Hello -

My site currently uses a header/footer/index.php to create the layout and keep design somewhat separate from the functions. I basically have a content area that is wrapped by this header/footer.php. I also have a few css files that control the fonts, positioning, and colors.

I would like to integrate phpMyFaq into my current site so that it appears in the content area. I'd rather not display the url here, but if you want to see it I can be reached via PM. Anyway, this means I have figure out where to put the following in either the index.tpl or index.php:

Code: Select all

include (fragments/header.php)
and

Code: Select all

include (fragments/footer.php)
I tried wrapping the index.php of phpMyFaq by inserting the aboves lines, but the styles.css for the faq took over and messed things up all over the site. Does this mean I should just remove the lines that conflict and rewrite some of my own CSS definitions to fix it? Additionally, I would rather not lose the head content generated by phpMyFaq, but my current header and footer have that information as well so it conflicts.

So does anyone know of a guide for this type of integration that could save me some time? Should I use a more simple and integrate-able faq script for my purposes?

Thanks in advance,
Wretch
wretch
Posts: 8
Joined: Wed Jun 28, 2006 4:07 pm

Post by wretch »

OK, I entered the include code into index.php and it works, as long as I edit the styles.css appropriately to remove any conflicting css.
wretch
Posts: 8
Joined: Wed Jun 28, 2006 4:07 pm

Post by wretch »

Everything is working fine in Firefox, but IE returns this error:

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /home/nt66/public_html/php_users/include/fragments/header.php:20) in /home/nt66/public_html/faq/inc/init.php on line 205

Warning: Cannot modify header information - headers already sent by (output started at /home/nt66/public_html/php_users/include/fragments/header.php:20) in /home/nt66/public_html/faq/index.php on line 92
Any suggestions?

you can view the FAQ here: http://www.newtrier66.com/faq

Anyone?
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

I think it woul be easier to add the includes in template/index.tpl instead of adding it into index.php.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
wretch
Posts: 8
Joined: Wed Jun 28, 2006 4:07 pm

Post by wretch »

Well, I moved the include code to the index.tpl. It didn't seem to recognize the php inside the .tpl file. It was ignored. I moved it back to index.php, and it worked. I just have to sort out the two errors I listed above and I should be good to go.

Any idea?
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

you have an output before including init.php which sets a cookie. That can't work. Include your header after the include of init.php.

PHP works inside the templates if you're activating it in the configuration.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
wretch
Posts: 8
Joined: Wed Jun 28, 2006 4:07 pm

Post by wretch »

Hi again Thorsten -

First of all, thank you for your replies.

I tried your advice by placing the include for the header after init.php inside the index.php and it made no difference. The errors were still there.

I then enabled php parsing in the template system and moved things around so that the includes were based inside the index.tpl file - to see if that would make any difference. After making the changes, it still doesn't recognize the php includes when I insert them into the index.tpl. My php is running as CGI, does that make a difference on how phpmyfaq makes use of htaccess to enable php-parsing in template files?

I can get the faq to wrap inside the header/footer if I use index.php, but then I get the header errors from the cookie. Can I disable/comment the cookie portion of phpmyfaq?
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Is the use of the IFRAME element an option?

Post by matteo »

Hi,
wretch wrote:Can I disable/comment the cookie portion of phpmyfaq?
This could break the PMF functionalities: we use 2 cookies one for the language setting and one for the internal user session id.
I could suggest you the <iframe> approach, if the old browsers compatibility is not an issue and this could be a good option 'cause PMF needs a CSS support provided by those browsers that support also the iframe element. Maybe you'll have others issues blocking the iframe solution: let us know.

Ciao,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
Thorsten
Posts: 15834
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Hi,

how does your template look like after inserting the PHP code? It will work with PHP as CGI, too.

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
wretch
Posts: 8
Joined: Wed Jun 28, 2006 4:07 pm

Post by wretch »

Hi Thorsten / matteo -

Thank you for the replies. No one has attempted to integrate this into an existing php template system? I have seen a few sites using iframes, but I would rather not go down that archaic path.

As you can see:

http://www.newtrier66.com/faq

...things are not too bad. Although, I still need to deal with the cookie issue somehow.

Even after I enabled php parsing for the .tpl files in PMF configuration, the include code was not recognized, and skipped over by php. The only way it reacts is when I include in index.php. I'm not sure what might be causing that. Anyway, thanks again for lending a helping hand. I'm sure I'll figure something out.

Wretch
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi wretch,
wretch wrote:Thank you for the replies. No one has attempted to integrate this into an existing php template system?
Yes, there are several examples on the net: the main difference is that they started moving their templates into the PMF ones.
wretch wrote:I have seen a few sites using iframes, but I would rather not go down that archaic path.
Why not if this could be the key for solving your issue? As said before, PMF needs to set 2 cookies so you have two choices for being able to upgrade your PMF installation in the future:
  1. hacking the PMF index,php file, as Thorsten said, for moving the set of the two cookies just before the first PHP output in your template: this is an option that take you far from having an easy upgrade process of PMF during the life of your site;
  2. removing from the index.tpl what is not needed such as the PMF banner and so on and using an iframe in your template to link the /path/to/PMF/index.php file: this will preserve both from cookies issues and from time issues about PMF upgrading
That's why I've suggested you the IFRAME solution.
wretch wrote:Even after I enabled php parsing for the .tpl files in PMF configuration, the include code was not recognized, and skipped over by php. The only way it reacts is when I include in index.php. I'm not sure what might be causing that.
Put this code below into the index.tpl file:

Code: Select all

...
</head>
<body dir="ltr">

<!-- DEBUG CODE - START -->
<div id="debug">

<?php
    print 'Fixme!';
?>
</div>
<!--  DEBUG CODE - END  -->
<div id="wrapper1">
    <div id="wrapper2">
...
If PHP parsing is enabled in your PMF configuration, in your HTML file you'll see (tested now):

Code: Select all

...
<!-- DEBUG CODE - START -->
<div id="debug">
Fixme!
</div>
<!--  DEBUG CODE - END  -->
...
For discovering IF the cookie issue is blocking the PHP parsing please try to test your PHP code into index.tpl within the context of a normal PMF setup, in order to understand if there is an issue in the PMF code.
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
wretch
Posts: 8
Joined: Wed Jun 28, 2006 4:07 pm

Post by wretch »

Well I kept at it, and finally noticed something I may have missed. Basically, I think I have resolved my cookie issue.

I enabled output_buffering in my php.ini and the cookies from phpmyfaq are now passed. Since I'm going to be running this FAQ as a superuser, by myself, and I'm going to disable account creation or whatever, getting rid of the errors (and the basic output of phpmyfaq) are all I needed as far as integration.

Now I just need to fix up the CSS and I should be good to go.

Thanks for all the help, and for the great script.
matteo
Posts: 572
Joined: Sun Nov 20, 2005 6:53 pm
Location: Italy

Post by matteo »

Hi,
wretch wrote:Well I kept at it, and finally noticed something I may have missed. Basically, I think I have resolved my cookie issue.

I enabled output_buffering in my php.ini and the cookies from phpmyfaq are now passed.
Good job, wretch! The ouput buffering is the key for correctly managing the order print of headers and body of the HTTP message: we didn't know that you were free to manage your php.ini so we didn't suggest you this solution: sorry for the misunderstanding...
wretch wrote:Now I just need to fix up the CSS and I should be good to go.
Feel free of posting here your files hierarchical structure for any help :)

Ciao,
Matteo
phpMyFAQ QA / Developer
Amazon.co.uk Wishlist
wretch
Posts: 8
Joined: Wed Jun 28, 2006 4:07 pm

Post by wretch »

No problem, I'm just glad to have found a resolution. If after some time this weekend I still cannot get the css working together, I'll make another post here for your excellent help.

Thanks again! :)
Post Reply