Submit Your Article Forum Rules

Results 1 to 4 of 4

Thread: Using php include

  1. #1
    Junior Member
    Join Date
    Dec 2004
    Posts
    1

    Using php include

    I'm placing a menu at the top of all my web pages and I will be making frequent additions to it. I don't want to make the changes to every web page every time I add or change the menu.

    What's the best technique for doing this? Could I use the php command as follows or is there a better way?


    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    echo file_get_contents('http://www.timestenmarketing.com/menu.htm');
    ?>

  2. #2
    Senior Member Evic's Avatar
    Join Date
    Jul 2005
    Posts
    173
    I would simply do the following:

    1. Make your menu howver you want, can be plain HTML, PHP, whatever.
    2. On all of your pages add the following line of code where you would like your menu displayed:
    Code:
    <? require_once("menu_file.php"); ?>
    You can take a look at the php.net documentation to determine if require, require_once, or include better suit your needs, but I am sure require_once is what you will want.
    Michael Wales

    My Blog: GibThis: Video Game Blog

  3. #3
    Junior Member
    Join Date
    Feb 2004
    Posts
    2
    Quote Originally Posted by Evic
    I would simply do the following:

    1. Make your menu howver you want, can be plain HTML, PHP, whatever.
    2. On all of your pages add the following line of code where you would like your menu displayed:
    Code:
    <? require_once("menu_file.php"); ?>
    You can take a look at the php.net documentation to determine if require, require_once, or include better suit your needs, but I am sure require_once is what you will want.
    Another thing you can do on each of your pages, if you have a common header, is define the HTML title that will be passed to "Header" code. This gives some differentiation in the browser history display.

    Example:

    $g_title='View Cart';
    include_once ('header.php');

    // which contains: echo "<title> $g_title </title>";

    include_once ('mainmenu.php');


    It may be handy.

    Ralph Frost

  4. #4
    Senior Member iany's Avatar
    Join Date
    Sep 2003
    Location
    Stirling, Scotland
    Posts
    339
    You could of course design your menu in CSS!

    Ian

Similar Threads

  1. Why php include does not show?
    By edhan in forum Web Programming Discussion Forum
    Replies: 25
    Last Post: 03-20-2010, 09:33 PM
  2. include or no include
    By subho in forum Web Programming Discussion Forum
    Replies: 52
    Last Post: 05-09-2009, 01:06 PM
  3. PHP include
    By jgarner in forum Web Programming Discussion Forum
    Replies: 2
    Last Post: 08-14-2006, 09:22 AM
  4. What is the best include method?
    By MrLeN in forum Web Programming Discussion Forum
    Replies: 5
    Last Post: 11-29-2004, 06:19 PM
  5. Using a SSI Include within an XSL document?
    By maddhacker24 in forum Web Programming Discussion Forum
    Replies: 6
    Last Post: 05-25-2004, 05:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •