Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- James Bates
April 11, 2006, 8:07 pm
rate this thread
who know's a little PHP, which I use to make smaller sites
semi-dynamic, I want to expand on what i'm currently doing but need
I currently use PHP to create a single included .php file that contains
the navigation, that knows via a variable hard-coded in the XHTML page,
what section that page is from and them marks the navigation <li> with
a class the highlights it.
Here's the code I currently use
//Section identifier - numbered or named'
Included navigation.php file
<li<?php if ($Section=="section1") echo " class=\"selected\""; ?>><a
So (eventually) I get to my question... Rather than having a variable
written into the top of each page, could I create a globals.php file
that's included from everypage that knows what section that page is is
from it's parent folder.
So if I hard-coded the folders/variables in this page, then the page
recognises which folder it's from and applys that variable to the
Any help much appreciated
Re: Dynamic site navigation
OK, but you may consider a change in the way you do things. Static Web
sites store content in files, with content embedded into presentation.
With a dynamic Web site, you have more options; you can (1) separate
contrent from presentation, and/or (2) choose to store content (whether
still attached to presentation or not) in files or in a database.
Note that the reverse is also possible. You can have an index.php
file, which contains navigation, include content drawn from files or a
Yes. If your globals.php is included into another file, the
superglobal variable $_SERVER['PHP_SELF'] will tell it into what file
it has been included.
Try this: create two files, a.php and b.php.
<?php include 'b.php'; ?>
echo '<p>PHP_SELF=', $_SERVER['PHP_SELF'],
'</p><p>__FILE__=', __FILE__, '</p>';
Then point your browser to a.php; the output will be:
In other words, b.php "knows" that its name is b.php and that it's been
included into a.php.