can any one help me__ php include file

Discussion in 'PHP' started by strgraphics, May 4, 2011.

  1. #1
    Hello Friends,

    i have 10 php files, in all files i need to include header, menu, footer.

    Currently, am writing include tags in all 10 pages, but is there any way to get header, menu, footer automatically with out including in every page.

    Like if we include in one baseLayout.php every php file must follows that, like Tiles concept in Struts.
     
    strgraphics, May 4, 2011 IP
  2. ruvenf

    ruvenf Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can have one php file, include each file once, change the content with each statement.
    like this:
    
    <? include 'header.php' ;
    include 'menu.php' ;
    ?>
    
    <?if ($_GET['page']=='home'){?>
    display html content
    <?}else if  ($_GET['page']=='anotherapage'){?>
    display html content
    <?}?>
    ...
    <? include 'footer.php' ;?>
    
    Code (markup):
    and then just modify the url for each page like this yourdomain.com?page=yourpagename

    hope it helps
     
    ruvenf, May 4, 2011 IP
  3. careerfield

    careerfield Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    also if you don't want anyone to be able to see your variable get function too easily try the re-write function in your htaccess file to change the url from yourdomain.com?page=yourpagename to yourdomain.com/page/yourpagename
     
    careerfield, May 5, 2011 IP
  4. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Yes,
    thanks ruvenf, careerfield

    both replies are pretty much helpful to me, thank you so much.
     
    strgraphics, May 6, 2011 IP
  5. careerfield

    careerfield Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    great i'm glad it helped! I didn't mention it before but I have noticed an increase in indexed pages on google when my url has been re-written with the rewrite function.
     
    careerfield, May 6, 2011 IP
  6. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    can any one of you, give me a small example

    Let i have a,php , b.php, and header.php, footer.php, and main.php...

    in main.php

    
    
    <? include 'header.php' ?>
    
    <?if ($_GET['page']=='a'){?>
    display html content
    <?}else if  ($_GET['page']=='b'){?>
    display html content
    <?}?>
    ...
    <? include 'footer.php' ;?>
    
    
    PHP:
    how can i give the url in the address bar....!!!!, am not clear about this guys.

    you mean may i give...

    yourdomain.com/main.php?page=yourpagename or... ?
     
    Last edited: May 6, 2011
    strgraphics, May 6, 2011 IP