how to: allow php in static pages 1.0.3 [phpBB3]

vondra vojtech’s static pages mod (v. 1.0.3) phpBB3 uses the built-in functions to generate content output, which prohibit the use of HTML and/or PHP. here’s a little hack which enables you to include your own php code in static pages, and have it parsed normally.

please note that allowing PHP on your static pages poses a BIG security risk, and you should only do it if (1) you can absolutely trust the admins of your board, and (2) you really need this.

if you just want to allow HTML in static pages, remove everything after “// end allow HTML”.

open page.php in your phpbb installation’s root folder and find this section:
// Parse the page content to transform BBCode
$content = generate_text_for_display($row['page_content'], $row['bbcode_uid'], $row['bbcode_bitfield'], 7);

now add the following code below it:
//allow HTML
   $replacearray = array(
      'before' => array("&lt;","&gt;","&quot;","<?"),
      'after' => array("<",">","\"","&lt;?")
   $content = str_replace($replacearray['before'],$replacearray['after'],$content);
//end allow HTML
//allow PHP   
   function execute($code) {
         $code = str_replace("<br />","\n",$code); // if you remove this, all the line-breaks in your page content's php-code will be converted into "<br />"s
         ob_start(); // don't output results, but store them in cache
         eval("?> $code"); // create html and php-output from page content
         $code = ob_get_contents(); // retrieve output from cache and store in variable
         ob_end_clean(); // clear cache
         $code = str_replace("\n","<br />",$code); // change line-breaks in HTML back to "<br />"s
         return $code;
      $content = execute($content);
//end allow PHP

One thought on “how to: allow php in static pages 1.0.3 [phpBB3]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.