Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board Different PHP Navigation Download Source Code
Author Details Code Information
Skepsis ( Matt )

Pinned 4 Codes
Posted 0 Coding Articles

Send A Message
View Coders Profile
Language PHP (Hypertext Preprocessor)
Expires Never
Length 1,282 Characters (58 Lines)
Password no password
Description

This is a way to use links like: http://www.example.com/index.php?whatever=page.
Normally navigation is done though the switch() function, but I decided to do it with arrays,
  1. <php
  2.  
  3. //-----------------------------
  4. // Defining the links.
  5. //-----------------------------
  6.  
  7.           $home           = 'news';
  8.           $pages           = array(
  9.                                                   'home'                               => array($home,                                         $home),
  10.                                                   'news'                              => array('news',                                         'news'),
  11.                                                   'about'                     => array('about',                                         'about'),
  12.                                                   'contact'                    => array('contact',                                        'contact'),
  13.                                                   );
  14.  
  15. //-------------------------
  16. // Load the module
  17. //-------------------------
  18.  
  19.                     if(array_key_exists($_GET['id'], $pages))
  20.                     {
  21.                               foreach($pages as $id => $filearray)
  22.                               {
  23.  
  24.                                         $file = "modules/".$filearray[0].".php";
  25.  
  26.                                                   if($_GET['id'] == $id && file_exists($file))
  27.                                                   {
  28.                                                             if (file_exists($file))
  29.                                                             {
  30.                                                                       include $file; // The file has been located and it's being included.
  31.  
  32.                                                             } else {
  33.  
  34.                                                                       die(); // The file didn't exist, therefore the script ends.
  35.                                                             }
  36.                                                   }
  37.                                }
  38.                     }
  39.  
  40. //-----------------------------------------------
  41. // Show the home page
  42. //-----------------------------------------------
  43.  
  44.                     else
  45.                     {
  46.                               $file = "/modules/" . $home . ".php";
  47.  
  48.                                         if(file_exists($file))
  49.                                         {
  50.                                                   require $file; // The file has been located and it's being included.
  51.                                         }
  52.  
  53.                                         else
  54.                                         {
  55.                                                   die(); // The file didn't exist, therefore the script ends.
  56.                                         }
  57.                     }
  58. ?>
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
Page 1 of 1
 
 
Part of the MyPingle Network
Development Blog :: Make A Donation :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents
Version 1.44.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved