I have been using PHP to navigate through my web pages. I have it set up so that each time the main index page is loaded, it loads the same header and footer and a different main section. The problem is, I have to have a start page such as index.html that passes a value to the index.php page. Maybe this will make it a little clearer.

Here is a link on the index.html page
<a href="index.php?nav=main">

Then when the index.php page is loaded, here is the script that executes

<?php
$nav = $HTTP_POST_VARS['nav'];

include ("chunks/header.chunk");
include ("chunks/$nav.chunk");
include ("chunks/footer.chunk");
?>

I would like to bypass the html page, and just have the PHP page load but when you load the PHP page the first time, it gives me the error that nav is undefined. Is there a better way to do what I am trying to accomplish, or is there something that I should add to make this work? I've tried adding an "if" statement, but I can't seem to get that to work. Thanks for the help.

    You can avoid that error by using something like this...

    <?
    if(!isset($_REQUEST['nav'])) {
    $nav = some_default_here;
    } else {
    $nav = $_REQUEST['nav'];
    }
    ?>
    

    This code sets $nav to a default value if the 'nav' variable is not passed via either the POST or GET methods.

    note: i would suggest using the $_REQUEST variable to access form variables 🙂

      Write a Reply...