PHP
  Home arrow PHP arrow Page 3 - Dynamic Generation of Menu Structures ...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Dynamic Generation of Menu Structures and JavaScript Rollovers in PHP
By: Chris Mospaw
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 9
    1999-05-10

    Table of Contents:
  • Dynamic Generation of Menu Structures and JavaScript Rollovers in PHP
  • Making a Template
  • Starting to Automate
  • The power of repetition
  • Ordering up a Menu
  • Adding Pages

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Dynamic Generation of Menu Structures and JavaScript Rollovers in PHP - Starting to Automate


    (Page 3 of 6 )

    The first step in automating the generation of these pages is to determine which page is being displayed. PHP comes with great environmental variable support, so determining this information is fairly straightforward.

    I've found that certain environmental variables are not uniformly supported on all implementations of PHP and all servers. Since my local development machine is a Windows 95 box and the Internet server a Unix box, the code that works on both is a bit convoluted. But it works on all installations I've tested it on.

    This code, which should be put at the top of the script, simply puts the name of the current page (with no file type suffix) into the $page variable:

    <? $page=getenv(SCRIPT_NAME) ; $page = split( "/", $page, 4); $page = "." . $page[3]; $page = split( "\.", $page, 3); $page = $page[1]; ?>

    You will probably have to adjust the "4" in line 3, and the "3" in line 4 since they refer to the depth of the directories on your machine, and that's likely to be different than mine. Inserting an echo "$page
    n"; between each line in the above snippet helps to track where things are going while adjusting lines 3 and 4 to work properly in your configuration.

    Now that we have the current page name without any file extensions, we're ready to start having PHP automate some items, such as the header graphic. Replace the "1 - Header Area" text with this line:


    <IMG SRC="<? echo "$page-h.gif"; ?>" WIDTH=596 HEIGHT=50 BORDER=0 ALT=""><BR>

    Notice the "inline" PHP in the SRC attribute, which just echoes the page name followed by the "-h" suffix. The height and width attributes are "hard wired" in, but can be changed at any time if the dimensions of the graphics change.

    Since this site will have more than one page, the script will have to know what the other pages in the site are named. For ease of maintenance, do this in a separate script called PAGES.HTML that is INCLUDEd in the main script. All PAGES.HTML does it to define an array containing the names of all the pages to be dynamically generated.


    <? $site_pages = array("index", "info", "clients", "contact" ); ?>

    There would be 4 pages in the dynamically generated menus on this particular site. Don't forget to insert:


    <? include "pages.html"; ?>

    near the top of the TEMPLATE.HTML script.

    More PHP Articles
    More By Chris Mospaw


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT