Stooney Posted January 13, 2007 Share Posted January 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 13, 2007 Share Posted January 13, 2007 if($location="home") include("home.php");if($location="contact") include("contact.php");for these, you should use double equal signs:if($location=="home") include("home.php");if($location=="contact") include("contact.php"); Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted January 13, 2007 Share Posted January 13, 2007 wouldnt that confilct with the index page of the about folder though?Ted Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 Ted, there is no about folder, let alone an index file in there. It's using mod_rewrite. Quote Link to comment Share on other sites More sharing options...
Stooney Posted January 13, 2007 Author Share Posted January 13, 2007 yea i meant ==. and thnx for the help, i'll go with mod_rewrite Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 13, 2007 Share Posted January 13, 2007 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 slashesif(substr($url, 0, 1) == '/'){ $url = substr($url, 1, strlen($url)-1);}//Get the url minus any GET varsif(strrpos($url, "?")){ $url = substr($url, 0, strrpos($url, "?"));}// Take out the trailing slashif(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 Indexif(!$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 htmlif($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 htaccessRewriteEngine onRewriteRule ^([A-Za-z0-9_/]+)$ /index.php [NC] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.