DasterMedia Posted February 4, 2010 Share Posted February 4, 2010 Hi Guys! In order of my little blog-website for my worldtour, I'm having a question about the following. My site starts with an index.html page, with a javascript-referer to 'index2.php?p=home' This is because i'm stuck with the next: Inside index2.php I'm taking the content from 'stand-alone?'-pages (only with text in it) I use the next code for it: <?php if (isset($_GET['p'])) { if($_GET['p']=='home') { include('home.html'); } elseif($_GET['p']=='page2') { include('page1.html'); } elseif($_GET['p']=='page1') { include('page2.html'); } }?> To show the text from home.html on the page (index2.php) the link must be like this: www.site.com/index2.php?p=home I'll ask if someone know (and will explain) me how to include 'home.html', without '?p=home'. So I can rename index2.php to index.php, and that home.html automatic will shown when no variabele is behind index.php Thanks! Yours sincerely, Danny Quote Link to comment Share on other sites More sharing options...
oni-kun Posted February 4, 2010 Share Posted February 4, 2010 { include('page2.html'); } } else { include('home.html'); //$_GET['p'] doesn't exist } It's most likely showing standalone text due to the fact it's being included, Therefor all interlinks will be offset to the page it is currently being included to. Quote Link to comment Share on other sites More sharing options...
Adam Posted February 4, 2010 Share Posted February 4, 2010 A better solution would be a switch, that way you can specify the "default" page (home.html): switch ($_GET['p']) { case 'page1': include 'page1.html'; break; case 'page2': include 'page2.html'; break; // add more pages here default: include 'home.html'; } In my opinion though an even better solution for this kind of setup would be to use an array. This would also allow you to add in a 404 style page when the user tries to access pages that don't exist: $valid_pages = array( 'home' => 'home.html', 'page1' => 'page1.html', 'page2' => 'page2.html' ); if (!isset($_GET['p'])) { $template = 'home.html'; } else { if (!array_key_exists($_GET['p'], $valid_pages)) { header("HTTP/1.0 404 Not Found"); $template = 'error.html'; } else { $template = $valid_pages[$_GET['p']]; } } include $template; Quote Link to comment Share on other sites More sharing options...
DasterMedia Posted February 4, 2010 Author Share Posted February 4, 2010 Thnx MrAdam, This is exactly the piece of code I wanted! It works very great! 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.