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
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
<!--- 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
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
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
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
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...