Please could someone help me out here ? I am very new to PHP and need some guidance. I have been following an 'includes' tutorial here: http://www.digital-web.com/articles/easypeasy_php_2/
The downloadable sample files include a way of hi-lighting the 'currentpage' state with PHP. Here's the problem: If I move the 'include navigation.php' code to ABOVE the 'include content' bit, the indicator stops working! I suspect it is something to do with the nesting of the if/ifelse/else code - but I have tried all that I know (nowt) to no avail. Can anyone help me out with an answer please?
Here's the 'includes code' that is based in index.php and calls all others - in the only order I can make the 'currentpage' PHP/CSSselector work: (If I move the line in question - the indicator stops!)
<?php
include ($_SERVER['DOCUMENT_ROOT'].'/inc/header.php');
// 1. Define an array of allowed $_GET values:
$pass = array('intro','page2','page3','page4');
// 2. If the page is allowed, include it:
if (in_array($GET['id'], $pass)) {
include ($SERVER['DOCUMENT_ROOT'] . '/inc/' . $_GET['id'] . '.php'); //this includes the content here I think...
}
// 3. If there is no $GET['id'] defined, then serve the homepage:
elseif (!isset($GET['id'])) {
include ($_SERVER['DOCUMENT_ROOT'] . '/inc/intro.php');
}
// 4. If the page is not allowed, send them to an error page:
else {
// This sends the 404 header:
header("HTTP/1.0 404 Not Found");
// This includes the error page:
include ($_SERVER['DOCUMENT_ROOT'] . '/inc/error.php');
}
include ($_SERVER['DOCUMENT_ROOT'].'/inc/navigation.php'); //this is the line in question!
include ($_SERVER['DOCUMENT_ROOT'].'/inc/footer.php');
?>
And here's the 'navigation.php' code sample:
<ul>
<li><a href="index.php?id=intro"<?php if ($thisPage=="intro") echo " id=\"currentpage\""; ?>>// intro</a></li>
<li><a href="index.php?id=page1"<?php if ($thisPage=="page1") echo " id=\"currentpage\""; ?>>// one</a></li>
<li><a href="index.php?id=page2"<?php if ($thisPage=="page2") echo " id=\"currentpage\""; ?>>// two</a></li>
<li><a href="index.php?id=page3"<?php if ($thisPage=="page3") echo " id=\"currentpage\""; ?>>// three</a></li>
</ul>
And the CSS
a#currentpage {
background: #666666;
color: #cc3333;
}
This at the top of each content page:
<?php
$thisPage = "page1"; //or whatever...
?>
Sorry for the long post - but I am tearing my hair out over this one. I bet the answer's simple for an expert!!
Thanks.
tim0fee