I've been using php for a while now, and I've made plenty of web sites 
in that time.  But there's been a nagging problem: the best way to put a 
layout and global code on each page.  My first site had two .txt files 
with header and footer code which were fopen()ed (with absolute paths!) 
and eval()ed on each page at the top and bottom - not the best option! 
 Even if I include()d them and made them .php, that approach would still 
have some problems.  No way to get the global code without the layout, 
and no way to die() and use the layout in functions without knowing what 
variables it needs (for globalizing them).  Right now, I'm doing 
something like this:

    <?php
    include("include.php"); //This contains the database connection code
    and whatever other global code, as well as the layout functions.
    doheader(); //This function contains the top of the layout.
    //Do whatever the page does
    dofooter(); //This function contains the bottom of the layout
    ?>

There are still problems with this, though.  No way to use global code 
at the bottom of the page, for one thing.  I've also considered 
something like:

    <?php
    $uselayout = true; //Set whether this page wants the layout or not.
    include("include.php");
    headercode(); //Database connection and whatever other global code
    that goes at the top, as well as the layout if $uselayout is true.
    //Whatever this page does goes here.
    footercode(); //Whatever global code that goes at the bottom goes
    here, as well as the layout if $uselayout is true.
    ?>

I can't find any problems with this approach, what are everyone;'s 
thoughts on this?

-- 
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt 
to decrypt it will be prosecuted to the full extent of the law.

Reply via email to