How to include the index page on every page?

Discussion in 'Programming' started by gandalf117, Mar 4, 2010.

  1. #1
    I am trying to create a master page in php. I have an index.php which has three divisions in it left, center and right. The left one contains the links. The center div holds the content. The right one contains adds. The simplified html of index.php looks like this:

    <body>
    <div class="left" id="left">
    <a href="index.php">Home</a>
    <a href="login.php">Log In</a>
    </div>
    <div class="center" id="center">
    </div>
    <div class="right" id="right">
    </div>
    </body>

    When the user clicks on Log In the page should go to login.php. The browser address bar should show login.php not index.php. But I still need the content from the index.php and therefore I assume the login.php should include index.php. I have seen this implemented on almost every website.

    The problem is that I want the content from the login.php to show inside the center div in the index.php. The obvious way to do this is to copy everything from the index page into the login.php, which is amateurish and certainly not the proper way to do this.

    So is there a way or a trick to include index.php in the login.php so that contents of the login.php show inside the center div on the index.php?
     
    gandalf117, Mar 4, 2010 IP
  2. darkdrgn2k

    darkdrgn2k Active Member

    Messages:
    159
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    NO...

    your opyion
    1) Get a templateing engine (Dreamweave has one... you can try SMARTY..)
    2) Cut up the site into sections, ie menu.php...
    then do an <? include "menu.php"; ?> on each page

    that way if you wanan chan ge the MENU you just change menu.php

    ie


    
    <body>
    <? include("menu.php");?> 
    <div class="center" id="center">
    </div>
    <div class="right" id="right">
    </div>
    </body>
    
    Code (markup):
    then your menu.php
    
    <div class="left" id="left">
    <a href="index.php">Home</a>
    <a href="login.php">Log In</a>
    </div>
    
    Code (markup):
     
    darkdrgn2k, Mar 4, 2010 IP
  3. darkdrgn2k

    darkdrgn2k Active Member

    Messages:
    159
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    actualy there is a cheat way i've used before
    Actualy many php applications sites use a diriivtive of this way

    create a template

    then break the template into PHP fucntion

    include the template file into your index.. logion. w/e and call the functions

    ie

    
    function Header() { ?>
    
    <body>
    <div class="left" id="left">
    <a href="index.php">Home</a>
    <a href="login.php">Log In</a>
    </div>
    <div class="center" id="center">
    <? } 
    funciton Footer { ?>
    <? } ?>
    </div>
    <div class="right" id="right">
    </div>
    </body>
    ?> 
    }
    ?>
    
    Code (markup):
    Then your page would be

    
    
    <? include "template.php";
    Header(); ?>
    MY Content
    <? Footer();?>
    
    Code (markup):
     
    darkdrgn2k, Mar 4, 2010 IP
  4. gandalf117

    gandalf117 Active Member

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    thanks guys,

    that works
     
    gandalf117, Mar 5, 2010 IP