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
 
 
Latest News About Coder Profile
Coder Profile Poll
Why do you get bored with programming?

Not enough time to do something productive
I run out of ideas
Too hard to show people my creations
Everything i do has too many errors, and it's too hard
I don't get bored!!!


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.49 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved