Documentation: Using With PHP

Issues and Work-Arounds

Using HTML Master Pages on a site that depends on PHP comes with certain easily remedied challenges.

Notice on the Stand-Alone Configuration walk-through tutorial page that we specifically do not map .php files to HTML Master Pages. While you may certainly do so, you might find that the overhead this causes can generate suboptimal site performance and may even "break" some of your pre-existing PHP code; particularly anything that depends on:

The short explanation for this is that -- above all else -- HTML Master Pages is focused on providing a "pure HTML" Master Pages solution to web page authors who may have no interest in dynamic page generation, which is an important but under-served classification of web page authors. In order to extend access to the underlying PHP language for the more adventurous web page authors while still providing core Master Page merging capability, HTML Master Pages provides a very simple eval() wrapper around every file it loads whenever that file contains a <?php tag. Using PHP in this way comes with some nontrivial processing overhead and the other minor nuisances listed above.

If you want to use PHP to dynamically construct your HTML documents, a well established best-practice exists which asserts a separation of your logic from your presentation code. When using HTML Master Pages, you can accomplish this by writing your classes and other business logic in .php files, then place your dynamic, view-generating code into .phtml files which are mapped to HTML Master Pages. Then, you need only direct web visitors to your:

Even with such well-separated code, you may still need an alternative to both $_SERVER['PHP_SELF'] and __FILE__, which is $_SERVER['PATH_TRANSLATED']. When the other values fail to give the value you need, try this one.