Jump to content

need advice


Stooney

Recommended Posts

I'm trying to decide a navigation method for a site.  What I'm wondering is if the following method is crap or not.

basic representation of index.php
[code]
include("header.php");

if(!isset($location))
    $location="home";


if($location="home")
    include("home.php");
if($location="contact")
    include("contact.php");

[/code]

then a link would look like
[code]
<a href="index.php?location=home">Home</a>
[/code]

so basically index.php will always show the header, menu, footer files and the actual content will be displayed based on $location.  Is there a better way to go about this?  i know GET doesn't seem that great.  thnx in advance
Link to comment
Share on other sites

You can do a similar thing with mod_rewrite. What I do is have my mod_rewrite direct anything to index.php, then index.php gets the url using $_SERVER['REQUEST_URI'], then include the relevant page.

So I have mysite.com/about/ - that will include about.php
Link to comment
Share on other sites

Chris, here's my code for my index.php It allows you include multiple files as you need, so you can get pretty advanced. Feel free to ask me if you need help with it, if you decide to use it.

[code]
$url = $_SERVER['REQUEST_URI'];
// Take off any initial slashes
if(substr($url, 0, 1) == '/'){
$url = substr($url, 1, strlen($url)-1);
}

//Get the url minus any GET vars
if(strrpos($url, "?")){
$url = substr($url, 0, strrpos($url, "?"));
}

// Take out the trailing slash
if(substr($url, strlen($url)-1, strlen($url)) == '/'){
$url = substr($url, 0, strlen($url)-1);
}else{
//header('Location: '.$siteURL.$url.'/');
}
// Split the url into an array
$url_parts = split('/', $url);

// If any page
$inc[0] = $basePath.'pages/'.$url_parts[0].'.php';
$incs = true;

// if index Index
if(!$url_parts[0] || $url_parts[0] == 'index'){
$inc[0] = 'base.php';  /// what you'd normally have on index.
$incs = true;
}

//if processing page, for forms, etc.
if($url_parts[1] == 'process'){
  $inc[0] = 'process_'.$url_parts[0].'.php';
  $incs = false;
}

//If the page is supposed to be wrapped in html
if($incs){
require_once($incPath.'header.php');
if($inc){
foreach($inc AS $in){
require_once($in);
}
}
require_once($incPath.'footer.php');
}else{
if($inc){
foreach($inc AS $in){
require_once($in);
}
}
}
[/code]

and my htaccess
RewriteEngine on
RewriteRule ^([A-Za-z0-9_/]+)$ /index.php [NC]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.