Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Dec 2002
    Location
    Misawa, Japan
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Include page containing variables and functions: Is this possible?

    After making a less than a few websites in HTML with the standard left navigation column...I've come to realize how tiring it is to complete a 15+ page site and later decide that I need to add another link in the nav column. Then adding it to all 15 pages and ftp'ing them only to change my mind later.

    The word efficiency doesn't come to mind

    After reading a few webmonkey tutorials I decided PHP was my savior.

    Perhaps I am approaching this in the wrong way, but I want to create a page with all the data that is often changed and placed on numerous places throughout the site.

    Below you can see how I attempted this by some variables and functions.

    An appropriate analogy would be the implementation of formatting a page via css stylesheet. Only I want to change the actual data displayed as opposed to the formatting.

    In my index page the code I use to call the functions is:

    <?php cenIndexLinks (); ?>

    (This code is in the head: <?php include(inc.php); ?> )

    As far as I can tell, the syntaxing is all correct...however I still recieve an error letting me know the inc.php page cannot be opened.

    The code below is the inc.php page containing the arrays and functions.

    <html>

    <body>
    <?php

    /* This first variable is called at the bottom of every page of the site as it will change every year */
    $copyright = "Copyright © 2003";

    /* I'm decided to store some articles and other information here just to see if I really understood the tutorial..this info isn't going to be dynamic */
    $articles = array (
    array ("name" => "cr0",
    "title" => "Title 1",
    "author" => "Author's Name",
    "date" => "00/00/00",
    "body" => ". . ."),
    array ("name" => "cr1",
    "title" => "Title 2",
    "author" => "Author's Name",
    "date" => "01/01/01",
    "body" => ". . . .")
    );

    /* This would be the part I'm most concerned with. This is the function I use to call the central index list (right nav link column) to be displayed on my page. This code snippet is inserted inside an HTML table' cell: <?php cenIndexLinks (); ?> */
    function cenIndexLinks () {
    echo ("<a href=link.html target=content>Link Text</a><br>");
    echo ("<a href=link.html target=content>Link Text</a><br>");
    echo ("<a href=link.html target=content>Link Text</a><br>");
    echo ("<a href=link.html target=content>Link text</a><br>");
    echo ("<a href=link.html target=content>Link Text</a><br>");
    }

    ?>

    </body>
    </html>

    Any help is greatly appreciated. I am making this site in order to learn PHP --not the other way around.

    Please let me know if I am unclear in any way. As English is not my first language.

  • #2
    Regular Coder
    Join Date
    Oct 2002
    Location
    Milwaukee, Wisconsin
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts
    lol there is a much easier way to do this im pretty sure
    have index.php
    then where you want your pages to show say(this is inbetween your HTML)
    <?php
    if($page != "") {
    include($page.".php");
    }
    else {
    include('home.php');
    }
    ?>

    then just make links like this for
    test.php
    <a href="index.php?page=test">TEST PAGE</a>

    i hope that helps a little bit

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Just a guess, try changing the file name to something like functions.inc.php then use

    include("functions.inc.php")

    and using that, make sure it's (functions.inc.php) in the same directory as the page you're including it in

  • #4
    New Coder
    Join Date
    Dec 2002
    Location
    Misawa, Japan
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried nightfire's suggestion of and interestingly enough, it didn't work. I thought the problem might have been with something I' did wrong however after re-checking both the index and and the functions.inc pages no change.

    I do not understand stooder's suggestion. From what I gather, there are test.php, page.php, home.php and index.php.

    I'm sorry but I really did understand what stooder said.

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Can you show the error? It might be that the include_path (set by the host on the server) might be different from the path you're using

  • #6
    New Coder
    Join Date
    Dec 2002
    Location
    Misawa, Japan
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The error at the top of the page is:

    Warning: Failed opening 'functionsincphp' for inclusion (include_path='') in /home/myusername/public_html/cos/index.php on line 7

    In the table cell for the php code to be printed a second error is:

    Fatal error: Call to undefined function: cenindexlinks() in /home/myusername/public_html/cos/index.php on line 44

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    And you're including the file as include("functions.inc.php") with the dots and quotes? Looks like from the error you showed, that it's trying to find a file called 'functionsincphp' instead of 'functions.inc.php'

  • #8
    New Coder
    Join Date
    Dec 2002
    Location
    Misawa, Japan
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's right, in the actual code I read:

    include("functions.inc.php")

    however the error is (and has previously) printed out that way. For some reason capitalization and the periods are removed.

    You would also notice that the error for cenIndexLinks(); is printed without caps. Although in the code for the include page and index page the caps are there.

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I have no idea I've copied the code you've put on here and tested it, I get no errors.

    The only time I get the errors
    Warning: main() [function.main]: Failed opening 'functions.inc.php' for inclusion (include_path='.;c:\php4\pear') in c:\ms\desktop\web\cf\index.php on line 2

    Fatal error: Call to undefined function: cenindexlinks() in c:\ms\desktop\web\cf\index.php on line 3
    Which is the same as yours, except maybe more detailed is if I've deleted the functions.inc.php page

  • #10
    Regular Coder
    Join Date
    Oct 2002
    Location
    Milwaukee, Wisconsin
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts
    hmm it looks like it is stripping the periods lol can you post your pages script please???


  •  

    Posting Permissions

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