Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP Question

  • 20-01-2011 03:14PM
    #1
    Closed Accounts Posts: 2,828 ✭✭✭


    What is the best practice for including common static website elements such as header, navigation and footer in PHP?

    Would I use a require_once and link to seperate files like, header.php, nav.php etc..

    Or would I be best off doing something like this
    [definitions.php]
    
    define('HEADER','');
    define('NAVIGATION','');
    define('FOOTER','');
    
    [index.php]
    
    require_once('definitions.php');
    
    echo HEADER;
    echo NAVIGATION;
    
    ....
    
    
    echo FOOTER;
    
    


Comments

  • Registered Users, Registered Users 2 Posts: 8,488 ✭✭✭Goodshape


    I think the definitions method is a bit messy. And means you're mixing HTML output in with your PHP definitions file.

    Create the header.php and footer.php and use <?php include('header.php'); ?>.


  • Closed Accounts Posts: 2,828 ✭✭✭Reamer Fanny


    Will do cheers :D


Advertisement