• home
  • forum
  • my
  • kt
  • download
  • PHP - Dynamic Includes

    Author: 2008-08-16 09:18:42 From:

    Add this code to a document and name it includes.php:
    CODE
    <?PHP
    // This determines that the string will be called "id"v $id = $_GET['id'];

    if(!$id){
    include"index.php";
    }
    elseif($id=="filename"){
    include"includes/filename.php";
    }
    // and if there is an incorrect string, we can direct to a 404 page

    else {
    include"404.php";
    }
    ?>


    -----------------------------------------------

    Now it is time to separate it so you people can understand it a little bit more.

    -----------------------------------------------
    This part of the coding tell the browser to use index.php as the first page that comes up. Most people will need to change this to the name of the file they want to appear on the index page. For example I would put the news into it so my code would me:

    CODE
    if(!$id){
    include"index.php";
    }


    My Example!

    CODE
    if(!$id){
    include"news.php";
    }



    Now thats out of the way, time to move onto:

    Now this gives the cool URL. Where it says elseif($id=="filename"){, this is what will be on the end of the URL for example; index.php?id=filename. Just change the name from filename to what you want.
    Now this bit is what it will include into the page; include"includes/filename.php";. Just change the path to the correct path to the file you want to include. Here is my example:

    CODE
    } elseif($id=="filename"){
    include"includes/filename.php";
    }



    My Example!

    CODE
    } elseif($id=="photoshop"){
    include"includes/photoshop_page.php";
    }



    Now this bit adds a 404 Error page, if the page you have put doesn't exsist:

    CODE
    else {
    include"404.php";
    }


    This will just include a 404 page if the page the browser is looking for doesn't exsist.

    ------------------------------------------
    Adding to your page
    Now I will explain how to add the includes to your page. Open up your index page or whatever your main page is, now go to the part where you want all the includes to show. Now put this code:

    CODE

    <?PHP include ("path/to/your/includes.php"); ?>



    And finally, how to add them to your links. This part is simple:

    CODE

    <a href="index.php?id=filename">Link<a">

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (7)
      Guestbooks (8)
      Image Manipulation (3)
      Installing PHP (5)
      Introduction to PHP (9)
      Link Indexing (6)
      Mailing List Management (8)
      Miscellaneous (10)
      Networking (6)
      News Publishing (6)
      OOP (8)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (5)
      Postcards (0)
      Randomizing (8)
      Redirection (8)
      Searching (6)
      Security (6)
      Site Navigation (9)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot