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!

3 Responses to “PHP Tutorial : Dynamic pages Switch and Case”

  1. Damon Says:

    thanks for the advice. I knew I was forgetting something


  2. Lukito Says:

    thank’s for your info.
    readers from Indonesia


  3. srisoftwarez Says:

    I have used this same method before reading this post …


Leave a Reply

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