SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Short include() question

    I use include() on all my pages to include pages with functions, variables etc. However, if I want to include a new file I have to insert the include() command on every page of my website.

    I was wondering if I can just include one file on each page and then add all the include commands in that file. Know what I mean?

    Is this a good idea or is it very ineffecient?
    Last edited by Dalixam; Mar 17, 2003 at 04:33.

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I don't see anything fundamentally wrong with that approach. It may take a few extra clock cycles to implement that strategy when loading your pages, but you are unlikely to notice it.
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great, thanks for your input. I'll give it a try then

  4. #4
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But then again, if the one page with ALL of your INCLUDEs for some reasons fails to load, you lose the lot LoL

    Create a TEMPLATE HTML file with your custom tags embedded with in the markup.

    Parse the template file, looking for the custon tags, such as TAG_DATE2DAY and replace with todays date.

    Another tag may be TAG_DOCBODY, whereby you call a function to create the content based on the $_GET or $_POST varaible passed, if any - thus you can create FORMS dynamically from the one function call:

    PHP Code:
    $Command $_GET['go'];
    .
    .
    if(
    strtolower($Command) == (string) 'PrintWelcom'
    PrintWelcome(); }
    else if(
    strtolower($Command) == (string) 'PrintGoodbye') { PrintGoodbye(); }
    else {
    PrintWhoAreYou();
    .

    For a complete working script:

    PHP Code:
    <?
        
        
    include_once("library/library.php");
        include_once(
    "templates/config/config.php");
        include_once(
    "../client/protected/classes.php");
        
        include_once(
    "authors.php");
        include_once(
    "products.php");
        include_once(
    "feedback.php");
        include_once(
    "catagories.php");
        
        
    $filename "templates/template-0.tpl";
        
        
    $file = @ fopen($filename"r"); 
        
        if(!
    $file)
        {
            echo(
    "<center style='font:11px verdana,arial;'>The template file $filename could not be found.</center>");
            exit();
        }
        
        while(!
    feof($file))
        {
            
    $html fgets($file1024);
            
    trim($html);
            
            if(
    ereg("<TAG_TITLE>"$html) > (int) 0)
            {
                echo(
    "SITE ADMINISTRATION");
            }
            else if(
    ereg("<TAG_NAVIGATION>"$html) > (int) 0)
            {
                
    ?>
                [ <a href="../" target="_self">Exit Administration</a> | <a href="index.php?Cmd=ShowFeedback" target="_self">Feedback</a> | <a href="index.php?Cmd=ShowAuthors" target="_self">Authors</a> | <a href="index.php?Cmd=ShowCatagories" target="_self">Catagories</a> | <a href="index.php?Cmd=ShowProducts" target="_self">Products</a> ]
                <?
            
    }
            else if(
    ereg("<TAG_BODY"$html) > (int) 0)
            { 
                
    $Cmd $_GET["Cmd"]; /* reference the GET HTTP prot first */
                    
                
    if(empty($Cmd)) 
                { 
                    
    /* failing this, then reference the POST HTTP prot instead */
                        
                    
    $Cmd $_POST["Cmd"]; 
                }
                
                
    /* products */
                
                
    if($Cmd == (string) "ShowProducts")                        { ShowProducts(); }
                else if(
    $Cmd == (string) "AddProduct")                    { AddProduct(); }
                else if(
    $Cmd == (string) "ModifyProduct")                { ModifyProduct(); }
                else if(
    $Cmd == (string) "DeleteProduct")                { DeleteProduct(); }
                else if(
    $Cmd == (string) "ShowAProduct")                { ShowAProduct(); }
                else if(
    $Cmd == (string) "DoDeleteProduct")                { DoDeleteProduct(); }
                else if(
    $Cmd == (string) "DoAddProduct")                { DoAddProduct(); }
                else if(
    $Cmd == (string) "ShowAProduct")                { ShowAProduct(); }
                else if(
    $Cmd == (string) "DoModifyProduct")                { DoModifyProduct(); }
                
                
    /* catagories */
                
                
    else if($Cmd == (string) "ShowCatagories")                { ShowCatagories(); }
                
                
    /* feedback */
                
                
    else if($Cmd == (string) "ShowFeedback")                { ShowFeedback(); }
                else if(
    $Cmd == (string) "ShowUserFeedback")            { ShowUserFeedback(); }
                else if(
    $Cmd == (string) "DeleteUserFeedback")            { DeleteUserFeedback(); }
                
                
    /* authors */
                
                
    else if($Cmd == (string) "ShowAuthors")                 { ShowAuthors(); }
                else if(
    $Cmd == (string) "DeleteAuthor")                { DeleteAuthor(); }
                else if(
    $Cmd == (string) "DoDeleteAuthor")                { DoDeleteAuthor(); }
                else if(
    $Cmd == (string) "AddAuthor")                    { AddAuthor(); }
                else if(
    $Cmd == (string) "DoAddAuthor")                    { DoAddAuthor(); }
                else if(
    $Cmd == (string) "ShowAnAuthor")                { ShowAnAuthor(); }
                else if(
    $Cmd == (string) "ModifyAuthor")                { ModifyAuthor(); }
                else if(
    $Cmd == (string) "DoModifyAuthor")                { DoModifyAuthor(); }
                else
                {
                    echo(
    "Choose an option from above links.");
                }
            }
            else
            {
                echo(
    $html);
            }
        }
            
        
    fclose($file);
        
    ?>
    Just include i.e. <TAG_NAVIGATION> within a TABLE cell of your HTML TEMPLATE file.

    Now you only have the one file to modify to change your web page layout/structure/logos whatever...


Bookmarks

Posting Permissions

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