PHP Tutorial : Dynamic pages Switch and Case

Do you want to keep all the content in only one single page to avoid searching and editing and opening tons of files for only one modification?
For that, we can do a single php dynamic page which will act as multiple pages. The form will be “page.php?pagename=home” or “page.php?pagename=contact”. We need the “switch and case” features from php. Here is the usage :

<?php
$page = $_GET['pagename'];

switch($page) {

case "home":

print "We are in the homepage now";

break;

case "contact":

print "Here is our contact page";

break;
}
?>

Add more dynamic php pages by doing a case like : case “products”: print “our products”; break;
Good luck!

This entry was posted in Usefull PHP and tagged , , , , , , . Bookmark the permalink.

One Response to PHP Tutorial : Dynamic pages Switch and Case

  1. Damon says:

    thanks for the advice. I knew I was forgetting something

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>