(Solved) How do I preload an include?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DeprecatedDiva
Forum Newbie
Posts: 24
Joined: Wed Aug 03, 2005 10:47 am
Location: NW Louisiana

(Solved) How do I preload an include?

Post by DeprecatedDiva »

I am using this code from http://digital-web.com/articles/easypeasy_php_2/. It works beautifully except I get the following error when the page is first loaded.
PHP Notice: Undefined index: id in C:\\Program Files\\Apache Group\\Apache2\\htdocs\\includes\\main.php on line 65
Now, I have read and I have searched but I am not grasping how to use the ISERROR.

Quick background: When the page is first loading, it is loading index.html.

INDEX PAGE:

Code: Select all

<?php 
// Enable output buffering
// More info: http://www.php.net/ob_start
ob_start(); 

// Brings in all pre-title elements
include ($_SERVER['DOCUMENT_ROOT'].'/includes/pretitle.php'); ?>

<title>The Biz Locator</title>
<style type="text/css"><!-- @import url("styles/stylesheet.css"); --> </style>
</head>

<body>
<div id="container">
<?php include ($_SERVER['DOCUMENT_ROOT'].'/includes/main.php'); ?></div>
</div>
</body>
</html>
MENU (in the main.php page):

Code: Select all

<ul>
<li><a class="menuitem" href="../index.html?id=home" title="Homepage">Home</a></li>
<li><a class="menuitem" href="../index.html?id=about" title="About">About Us</a></li>
<li><a class="menuitem" href="../index.html?id=contact" title="Contact">Contact Us</a></li>
<li><a class="menuitem" href="../index.html?id=sponsors" title="Sponsors">Sponsors</a></li>
<li><a class="menuitem" href="../index.html?id=polpro" title="Contact">Policies/Procedures</a></li>
<li><a class="menuitem" href="../index.html?id=form" title="Contact">Testing Form</a></li>
</ul>

Only when I click one of my menu selections does it bring the following code into play.

Code: Select all

59  <?php 
60
61  // Define an array of allowed $_GET values:
62      $pagename = array('home','about','contact','sponsors','polpro','form','welcome',);
63  
64  // If the page is allowed, include it:
65      if (in_array($_GET['id'], $pagename)) {
66      include ($_SERVER['DOCUMENT_ROOT'] . '/includes/' . $_GET['id'] . '.php');
67      }
68
69  // If there is no $_GET['id'] defined, then serve the homepage:
70      elseif (!isset($_GET['id'])) {
71       include ($_SERVER['DOCUMENT_ROOT'] . '/includes/home.php');
72    }
73
74  // If the page is not allowed, send them to an error page:
75    else {
76     // This sends the 404 header:
77        header("HTTP/1.0 404 Not Found");
78     // This includes the error page:
79        include ($_SERVER['DOCUMENT_ROOT'] . '/includes/error.php');
80  }
81  ?>
So, I figure I need to load index.html?id=home.php first... but how?

TIA,
Last edited by DeprecatedDiva on Mon Aug 08, 2005 6:36 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

change line 65 to

Code: Select all

if (isset($_GET['id']) && in_array($_GET['id'], $pagename)) {
Last edited by John Cartwright on Mon Aug 08, 2005 7:26 pm, edited 1 time in total.
DeprecatedDiva
Forum Newbie
Posts: 24
Joined: Wed Aug 03, 2005 10:47 am
Location: NW Louisiana

Post by DeprecatedDiva »

Thank you JCart. That worked beautifully.
Post Reply