MyBB Community Forums

Full Version: how to php include header
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I have just installed the myBB program and everything seems to work great.

I want to use a php include for the header that I already have for all pages on my website like this:

<?php include '../header.php'; ?>

In the Edit Template, it doesn't accept php include. How do I insert php include in the template or another way around?

That goes the same for the footer that I want to use my existing footer via php include.

Thanks
You would be better off pasting your header code into the header template as this will essentially do the same thing.
I had the same problem but found a way around it.
MyBB does not allow PHP code in the template system. Dodgy Only HTML. You could try this plugin first http://community.mybboard.net/thread-31860.html , but if that doesn't work then you could try this other way.

It's not easy but it works. In every file such as index.php, usercp.php, misc.php etc. (all the files that are visible to the user) look for
all the "output_page" functions. It will look something like this


eval("\$index = \"".$templates->get("index")."\";");
output_page($index);

and add your php includes as needed like this, surrounding the entire output_page and eval.

include 'header.php';

eval("\$index = \"".$templates->get("index")."\";");
output_page($index);

include 'footer.php';

Also note that there can be 10+ of these in one file so that means lots and lots of copying and pasting. You just have to come up with a systematic way of doing it and you can get it done in a day.

Then delete the unnecessary elements from your MyBB header template as you no longer need alot of that. Just keep the welcome block stuff and get rid of any header images and things.
Assuming your header.php ends with something like <div id="content"> and your footer.php begins with the corresponding end div </div>
then all the forum content will get sandwiched in there.

HEADER.PHP STUFF
<div id="content">
MYBB FORUM WILL BE HERE
</div>
FOOTER.PHP STUFF

I will warn you that this takes lots of time to do, and is not necessarily the best route. It can cause headaches later on when trying to update MyBB as you cannot just upload all the new files over top of your modified versions. You would lose all your work. Thus you have to manually make the changes for each new version.

It also can take quite a bit of playing around with this, as your result may vary depending on your existing site design.

I would recommend doing this ONLY if your header and footer have PHP code in them. If it is just straight HTML in your header and footer then do like TimB. suggested and just simply copy and paste the HTML into the header and footer templates in MyBB.
(2010-02-18, 11:00 PM)miimario Wrote: [ -> ]I had the same problem but found a way around it.
MyBB does not allow PHP code in the template system. Dodgy Only HTML. You could try this plugin first http://community.mybboard.net/thread-31860.html , but if that doesn't work then you could try this other way.

It's not easy but it works. In every file such as index.php, usercp.php, misc.php etc. (all the files that are visible to the user) look for
all the "output_page" functions. It will look something like this


eval("\$index = \"".$templates->get("index")."\";");
output_page($index);

and add your php includes as needed like this, surrounding the entire output_page and eval.

include 'header.php';

eval("\$index = \"".$templates->get("index")."\";");
output_page($index);

include 'footer.php';

Also note that there can be 10+ of these in one file so that means lots and lots of copying and pasting. You just have to come up with a systematic way of doing it and you can get it done in a day.

Then delete the unnecessary elements from your MyBB header template as you no longer need alot of that. Just keep the welcome block stuff and get rid of any header images and things.
Assuming your header.php ends with something like <div id="content"> and your footer.php begins with the corresponding end div </div>
then all the forum content will get sandwiched in there.

HEADER.PHP STUFF
<div id="content">
MYBB FORUM WILL BE HERE
</div>
FOOTER.PHP STUFF

I will warn you that this takes lots of time to do, and is not necessarily the best route. It can cause headaches later on when trying to update MyBB as you cannot just upload all the new files over top of your modified versions. You would lose all your work. Thus you have to manually make the changes for each new version.

It also can take quite a bit of playing around with this, as your result may vary depending on your existing site design.

I would recommend doing this ONLY if your header and footer have PHP code in them. If it is just straight HTML in your header and footer then do like TimB. suggested and just simply copy and paste the HTML into the header and footer templates in MyBB.

mm adding a header and footer was my next step - glad i found this post - curious as to why i can't add php code to the templates? it would make things much easier!
It's for security reasons that you can't add PHP.
Why? Only admins can edit the templates. I'd like to see PHP support as well, because I had to write a plugin just to include a few lines of PHP.
(2010-06-10, 07:43 PM)patrick Wrote: [ -> ]Why? Only admins can edit the templates. I'd like to see PHP support as well, because I had to write a plugin just to include a few lines of PHP.
Problem is that you can pull information such as database passwords up with PHP in the templates. If you got a forum and you got other administrators of course you should trust them but I wouldn't like them to have full access to my database(s).
hmmm.... there should be some kind of work around for this ....... right?

maybe set a separate password to edit/view the templates that can only be tied to one person?

brainstorm people brainstorm Big Grin
Pages: 1 2