I’ve been using this method to work around static page’s or domain restrictions. The logic is actually really simple and you can employ in a variety of different languages so let me just explain it out.

The dynamic page (the bait) is usually a static page or file. This reason this file needs to be static could be because you using a restrictive CMS or that the file being loaded needs to live on your domain. Whatever the case, this file is where a conditional statement would go (the switch). I’m going to use the example of a wordpress theme to illustrate.

The single.php file in your wordpress theme is what is used to display the one up view of a blog post. What happens when you need to display blog posts in different ways? WordPress recommends that you create post types and sort via post type. If you willing to trawl through the codex and write a function to your functions.php file then by all means go for it. If thats a lot more work than what the end result is worth to you, write a simple if statement into your single.php.

The code logic would work a little bit like this (I’m leaving out specific language so it’s a bit more accessible):


if (category == ‘article’) {
	include (single-article.php);
if (category == ‘quote’) {
	include (single-quote.php);


So from the above code you can see, when single.php is requested, it asks what category the post falls into. If it falls into an article category, then it serves single-article.php. If its a quote category then it serves single-quote.php. Essentially, single.php becomes those external files for that specific user session. You can customize the external files as you wish.

Another good reason to use this technique is to overcome domain restrictions. For instance in the Wikilynx project, iframes called the actual wikipedia article for reading. This pulling of external content was quickly blocked by the wikipedia servers for security reasons. I thus wrote a php file that existed as a faux wikipedia article. It would pull in the wikipedia content and then get displayed through the iframe. This not only overcame the security restriction but gave me full access over the content itself. So I parsed that data and change the links within the page to respond to the dynamic graph I had set up.

There is a danger to using this technique on larger scale websites. Every conditional statement requires CPU power to compute. Throw enough user’s at your server and it will eventually crash. As mentioned before, only use this technique if the end result is not worth the hassle of a full blown CMS or framework specific solution.

If you have any questions about this technique or have used it successfully somewhere awesome let me know on twitter @ManeeshChiba