Dynamic content in php by switching it out with other PHP file

Code with C | Programming: Projects & Source Codes Forums PHP Dynamic content in php by switching it out with other PHP file

This topic contains 1 reply, has 1 voice, and was last updated by  ShikhaTan 2 years, 6 months ago.

  • Author
  • #11003


    Hey guys is there a way to to make your main content block dynamic, by switching it out with other .php files instead of including your header, footer and navigation on each php page? Or is including the header, footer, and nav the prefered way?

    Plus if the content is dynamic will the page address that switches out the content change? If not will that mean if someone directly types or guess your dynamic page (i.e page.php), it’ll load on its own instead of popping up under the same parent page that calls it dynamically?

  • #11004


    PHP was made for this exact purpose; dynamic web pages which can serve content on the fly if partnered with a language such as javascript.

    What you want to do here is detect which page the user is on (via the URI) and then use javascript with ajax to dynamically update the GUI with different pages.

    With including the same content on each page, keep it DRY and use includes to insert content to the page. So you could have a base.php page with:

You must be logged in to reply to this topic.