2010-04-01, 06:13 PM
In this tutorial you will learn how to make all of your site's pages run your MyBB tasks, as well as how to parse .html files for PHP code. Why would you want to do either of those you ask?
Well, for the tasks, this means that they will be more likely to run on time. Also they will be run when someone visits your SITE, but without visiting your FORUM.
EDIT:
I've come across a simpler way that doesn't require the PHP parsing of your .html files. Thanks frostschultz of MyBBoard.net for pointing out that I overthought this far too much.
Instead of all of the above... just do this in your footer:
For the PHP code inside .html, it allows for a LOT more flexibility in your site's structure. Including putting login boxes and other such PHP powered constructs anywhere in your site.
This tutorial assumes several things, but attempts to explain them in as generic of terms as possible.
Assumptions:
Step 1 - Setting up your web server to read & parse PHP code written into your html files:
In your website's root directory (usually /public_html or similar in your ftp) open your .htaccess file for editing and place the following line at the end of it (or grouped with any other AddType lines you may see)
Step 2 - Placing the PHP code into the footer of html files:
This is the basic code you will be putting in your files, in fact in most cases you can use this without changing anything other than the /bb to whatever you are using for your site. Place this inside the <footer></footer> tags of your page. If you do not have them, they go after </body> and before </html>.
Remember to change the /bb to whatever you're using. If you're using /forums change it to that. If you have the forum in your website's root, then just remove /bb completely leaving ./global.php in that line.
Now, what about files you want this in that aren't in the web root, and are in fact in their own subfolder? For example:
www.example.com/gallery/index.html
You simply need to change the require_once so that it backs up to the root level before descending. You do this by adding a ../ for every level you need to go up.
Using our example above, and saying our forum is in /bb the require_once line would look like this:
Another example:
www.example.com/gallery/upload/admin/index.html
Now, here we're 3 levels deep: gallery, upload, and admin.
So our require_once line would become:
Please use you common sense in adjusting this to suit each file. It doesn't take a lot of though to figure out what exactly you need for that line.
Step 3 - Adding this to PHP files:
PHP files I'm only going to cover in the most general terms. If you don't know at least some PHP I suggest you only do this in PHP files that output an html page and only then if you can find where the footer is, or belongs, in the html inside the PHP. Otherwise this is too complex to explain without explaining a lot of PHP.
In many cases you will have a mixed PHP/html file. In others you will have PHP that is using echo to send html. In either of these cases you should be able to find the footer tags, or the closing body tag. In such cases please refer to the instructions above for html footers.
If you want to add this to OTHER PHP pages that have output, but are using straight PHP...
Well, its pretty much safe to put this code anywhere other things are being echoed to the user. However, this is where common sense comes in. I wouldn't put it near anything clickable for example.
Closing notes:
In many cases it is safe to include this at the tail end of your body section, just before your closing tag. So you can TRY inserting this there. I've yet to find a single case of this causing an issue, but you may. So always test it first.
Well, for the tasks, this means that they will be more likely to run on time. Also they will be run when someone visits your SITE, but without visiting your FORUM.
EDIT:
I've come across a simpler way that doesn't require the PHP parsing of your .html files. Thanks frostschultz of MyBBoard.net for pointing out that I overthought this far too much.
Instead of all of the above... just do this in your footer:
<img src="http://www.urltomyforums.com/forum/task.php" />
/EDITFor the PHP code inside .html, it allows for a LOT more flexibility in your site's structure. Including putting login boxes and other such PHP powered constructs anywhere in your site.
This tutorial assumes several things, but attempts to explain them in as generic of terms as possible.
Assumptions:
- You have a main site in your website's root directory.
- Your forum is in a subfolder such as /forum or /bb. I will use /bb in my examples here.
- You know some basic HTML so you will understand what I mean when I say things like, "Put the following in your footer".
- You have common sense. While I realize that is an assumption that can bite me in the rear, I would hope that you do.
Step 1 - Setting up your web server to read & parse PHP code written into your html files:
In your website's root directory (usually /public_html or similar in your ftp) open your .htaccess file for editing and place the following line at the end of it (or grouped with any other AddType lines you may see)
AddType application/x-httpd-php .html
Step 2 - Placing the PHP code into the footer of html files:
This is the basic code you will be putting in your files, in fact in most cases you can use this without changing anything other than the /bb to whatever you are using for your site. Place this inside the <footer></footer> tags of your page. If you do not have them, they go after </body> and before </html>.
<!-- The following piece of code allows MyBB to run scheduled tasks. DO NOT REMOVE -->
<?php
define("IN_MYBB", "1");
require_once "./bb/global.php";
echo $task_image;
?>
<!-- End task image code -->
Notes:Remember to change the /bb to whatever you're using. If you're using /forums change it to that. If you have the forum in your website's root, then just remove /bb completely leaving ./global.php in that line.
Now, what about files you want this in that aren't in the web root, and are in fact in their own subfolder? For example:
www.example.com/gallery/index.html
You simply need to change the require_once so that it backs up to the root level before descending. You do this by adding a ../ for every level you need to go up.
Using our example above, and saying our forum is in /bb the require_once line would look like this:
require_once "../bb/global.php";
You'll notice that when doing this the ./ before the bb changes to a ../ - when going upwards through folders we eliminate the ./ completely and replace it with however many ../ we need to reach the website's root.Another example:
www.example.com/gallery/upload/admin/index.html
Now, here we're 3 levels deep: gallery, upload, and admin.
So our require_once line would become:
require_once "../../../bb/global.php";
Please use you common sense in adjusting this to suit each file. It doesn't take a lot of though to figure out what exactly you need for that line.
Step 3 - Adding this to PHP files:
PHP files I'm only going to cover in the most general terms. If you don't know at least some PHP I suggest you only do this in PHP files that output an html page and only then if you can find where the footer is, or belongs, in the html inside the PHP. Otherwise this is too complex to explain without explaining a lot of PHP.
In many cases you will have a mixed PHP/html file. In others you will have PHP that is using echo to send html. In either of these cases you should be able to find the footer tags, or the closing body tag. In such cases please refer to the instructions above for html footers.
If you want to add this to OTHER PHP pages that have output, but are using straight PHP...
Well, its pretty much safe to put this code anywhere other things are being echoed to the user. However, this is where common sense comes in. I wouldn't put it near anything clickable for example.
define("IN_MYBB", "1");
require_once "../bb/global.php";
echo $task_image;
Closing notes:
In many cases it is safe to include this at the tail end of your body section, just before your closing tag. So you can TRY inserting this there. I've yet to find a single case of this causing an issue, but you may. So always test it first.