Adding ads in a fluxBB or punBB forum

Forums usually do not make a lot of money, unless they make very heavy traffic because most of visitors are habit to it and ignore the ads. If your forum is big enough you can put ads in the template as long as a few precautions are taken.

Inserting the Adsense code

The idea comes from the punBB forum.
Create a PHP file with the adsense code inside.

  1. The name could be ads.php.
  2. This file must be stored into the include/user directory.

The code may be created with an echo statement:

echo '<script type="text/javascript">...Adsense content...</script>";

Now go to the directory include/template and edit the file main.tpl.
Add this line (you can try various placements):

<pun_include "ads.php">

How to block forbidden words

It is forbidden by the rules of the program to use Adsense on a page that display words related to "p_rn_graphy" or "casin_" for example. But in a forum it is not always easy to control the content of the post as we cannot read all of them as soon they are posted. Consequently advertisements could be displayed on pages where spammer have introduced these forbidden terms.

But you can prevent a spammer to use such words very easily with punBB.

At first, define the list of forbidden words and put them into an array:

$words = array(
     "first word",
     "second word",
     "etc." );

Then create a code to block such words:

foreach($words as $word)
  if($stristr($message, $word) !== false)) 
     $errors[] = 'Forbidden words in post. Access denied';

This code must be inserted in the post.php file, after the code to parse the content of the message:

if ($pun_config['p_message_bbcode'] == '1' && 
  strpos($message, '[') !== false && 
  strpos($message, ']') !== false)
  require PUN_ROOT.'include/parser.php';
  $message = preparse_bbcode($message, $errors);

and before the message is sent to the database in the block that begins by:

require PUN_ROOT.'include/search_idx.php';

You can allow the administrator to bypass the code by inserting the code into a such condition:

if (!$is_admmod)

This is for punBB.
For other CMS such as phpBB, SMF, IPB, the code to insert is similar but the names of variables differ.

More infos