View Full Version : Include page containing variables and functions: Is this possible?

03-26-2003, 04:28 AM
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.



/* 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>");



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.

03-26-2003, 06:00 AM
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)
if($page != "") {
else {

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

i hope that helps a little bit

03-26-2003, 12:34 PM
Just a guess, try changing the file name to something like functions.inc.php then use


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

03-26-2003, 08:26 PM
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.

03-26-2003, 08:34 PM
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

03-26-2003, 08:42 PM
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

03-26-2003, 09:12 PM
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'

03-27-2003, 12:21 AM
That's right, in the actual code I read:


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.

03-27-2003, 12:53 AM
I have no idea :confused: 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

03-27-2003, 03:40 AM
hmm it looks like it is stripping the periods lol can you post your pages script please???