Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using a header-file with links in it over multiple folders

512 views
Skip to first unread message

Job

unread,
Mar 19, 2004, 3:20:26 AM3/19/04
to
Hi,

I'm struggling with the following:

I have a header.php file with a menu that links to, let's say 10 pages.

I have an index.php in my site-root.

I have a folder 'pages' with 4 'files.php' , and in there a subfolder
'subpages' with 5 more 'file.php'


structure like so:

header.php
index.php
FOLDER:
page1.php
page2.php
page3.php
page4.php
SUBFOLDER:
page1.php
page2.php
page3.php
page4.php
page5.php


I want to be able to include my one header.php in all these pages, but
this gives me problems: if I put header.php in 'folder' only the links
within the folder-pages work, not to index.php or the subfolder pages.
Same when I put header in root or subfolder.

I somehow have to dynamically create the links in the header by checking
paths/folders etc. but don't know how to approach this.

Any suggestions?

Thanks,

Job

Rocky

unread,
Mar 19, 2004, 5:33:56 AM3/19/04
to
In article <c3eau6$jdb$1...@reader08.wxs.nl>, job...@hotmail.com says...

One way is to use ...

require ("$_SERVER[DOCUMENT_ROOT]/header.php");

in all your files.

page1....n.php
<?php
require ("$_SERVER[DOCUMENT_ROOT]/header.php");

rest of your code
?>

Do a ..
<?php
echo ("$_SERVER[DOCUMENT_ROOT]/header.php");
?>
..to check the path.

HTH :-)

Rocky

http://www.rockymania.org.uk/

Carl Wiles

unread,
Mar 19, 2004, 5:44:27 AM3/19/04
to
How about changing your whole approach. Instead of including the header.php
in the page.php files, why not include the pages and subpages into your
header file.
First i would have to presume that your "header.php" file is basically your
navigation etc, being included in your index.php file as well. First, you
would need to rename index.php to say, main.php, and rename header.php to
index.php. then you would use your already written "header code" and add the
following code, or something similar afterwards:


<!--- your code here --->
<?php
if(!$page) {
$page = "main.php";
}elseif(@!include($page)){
echo "We're sorry this page is currently unavailable.";
}
?>
Now, all you need to do is change your hyperlinks in your navigation system
to reference certain pages, defining the $page varibale via the URL. an
example for a couple pages is below:

<a href="?page=main.php>Main</a>
<a href="?page=folder/page1.php>Page One</a>
<a href="?page=folder/page2.php>Page Two</a>
<a href="?page=folder/subfolder/page1.php>SubPage One</a>
<a href="?page=folder/subfolder/subfolder/page1.php>Sub-SubPage One</a>


(Realize that $page must also contain the relative path to the file if it is
in a subfolder, for example, main.php is in the same folder as index.php, so
there is no path, but page1.php is in FOLDER so $page would need to be set
to folder/page1.php, as shown in the examples above.)

I hope this helps you out, and makes your life easier!


~DreamWraith
http://www.dead6.net/


"Job" <job...@hotmail.com> wrote in message
news:c3eau6$jdb$1...@reader08.wxs.nl...

Job

unread,
Mar 19, 2004, 6:08:58 AM3/19/04
to
Thanks Carl, hadn't thought of this, but it sounds pretty OK!. Will
certainly try it!

Job

Job

unread,
Mar 19, 2004, 6:10:13 AM3/19/04
to
Hi Rocky,

thanks, will try it later! Carl Wilkes solution also sounds pretty ok to
me. Will play around and see what works best for me!

Job

Job

unread,
Mar 19, 2004, 6:24:54 AM3/19/04
to
Trying it, I run into the following:

In the original way, in my header I have:
<title><?php echo $doctitle; ?></title>

so a page would start with:
<?php
$doctitle = "title of current page";
include('header.php');

- rest of page here -
?>

But if I turn it around like you suggest, I can't define a title, cause
the page starts with the header-code(including the title-tag), and then
comes the <?php include($page) ?>

How did you solve this?

Job

Kreso

unread,
Mar 19, 2004, 8:17:12 AM3/19/04
to

why do you have so many (main)php pages?
why dont you use index.php to handle all?
so, if somebody wants content XX, check it in index.php and include it

<?
include "header.php";

if ($_GET['link'] == "XX")
include "folder/sub/index.php";

this is just semple. Culd be much better

this way you dont need to know where is header.php.


--
kreso
http://www.plus.hr/cgi-bin/aff/g.o/gdprom
www.gdprom.com


Carl Wiles

unread,
Mar 19, 2004, 3:25:52 PM3/19/04
to
there are a couple approaches.

The easiest is probably to do the following:


<?php
if($page=="page1.php"){
$doctitle = "This is Page One";
}elseif($page=="subpage1.php"{
$doctitle = "This is SubPage One";
}elseif( etc, etc, etc.
?>
<html>
<head>
<title><?php echo($doctitle); ?></title>
</head>
<body>
<?php include('header.php'); ?>

and so on

~DW


"Job" <job...@hotmail.com> wrote in message

news:c3elo2$4cb$1...@reader08.wxs.nl...

0 new messages