zavin Posted March 20, 2009 Share Posted March 20, 2009 How do you write the php pages to load as "index.php?on=home" instead of it loading a new page as "home.php"? Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted March 20, 2009 Share Posted March 20, 2009 are you talking about a clickable link, or a header redirect, or submitting a form ? how exactly are you getting from one page to the other in this case Quote Link to comment Share on other sites More sharing options...
Zhadus Posted March 20, 2009 Share Posted March 20, 2009 Inside of index.php, you have a script like this: $page = $_GET['on']; require_once("$page.php"); Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 20, 2009 Share Posted March 20, 2009 you might want to try this $page = $_GET['page']; if(isset($page)) { switch($page) { case 'home': echo "this is home"; break; case 'page2': echo "this is page2"; break; case 'page3': echo "this is page3"; break; } } else { echo "this is home page which is the default"; } <a href="index.php">home</a> <a href="index.php?page=page2">Page 2</a> <a href="index.php?page=page3">Page 3</a> try this and let me know Quote Link to comment Share on other sites More sharing options...
zavin Posted March 20, 2009 Author Share Posted March 20, 2009 are you talking about a clickable link, or a header redirect, or submitting a form ? how exactly are you getting from one page to the other in this case In most cases it will be a link. Inside of index.php, you have a script like this: $page = $_GET['on']; require_once("$page.php"); Will I need to add anything to each page after that as well? Quote Link to comment Share on other sites More sharing options...
zavin Posted March 20, 2009 Author Share Posted March 20, 2009 you might want to try this $page = $_GET['page']; if(isset($page)) { switch($page) { case 'home': echo "this is home"; break; case 'page2': echo "this is page2"; break; case 'page3': echo "this is page3"; break; } } else { echo "this is home page which is the default"; } <a href="index.php">home</a> <a href="index.php?page=page2">Page 2</a> <a href="index.php?page=page3">Page 3</a> try this and let me know It seems that this is the long way to do it. I can see how it may work, but when I'm done with my site I will have over 30 pages. I was hoping for a shorter solution. Quote Link to comment Share on other sites More sharing options...
Zhadus Posted March 20, 2009 Share Posted March 20, 2009 irkevin gave some useful information, but what I think you're looking for is a mix: $page = $_GET['page']; if((isset($page)) && ($page != '')) require_once("$page.php"); else require_once('default.php'); That is just a basic shell. As long as 'page' is set, you'll open up that page, otherwise it goes to default.php. This allows you to load in a single navigation file in the index, but show up on the same page. You don't need to include anything additional, but here is an example of what a basic site would look like with a header, navigation, main page, and footer: <?php $page = $_GET['page']; echo '<table><tr><td colspan="2">'; require_once('header.php'); echo '</td></tr><tr><td>'; require_once('navigation.php'); echo '</td><td>'; if((isset($page)) && ($page != '')) require_once("$page.php"); else require_once('default.php'); echo '</td></tr><tr><td colspan="2">'; require_once('footer.php'); echo '</td></tr></table>'; ?> I hope that puts things into perspective. Quote Link to comment Share on other sites More sharing options...
irkevin Posted March 20, 2009 Share Posted March 20, 2009 Well, there might ber some sort of solution, but that should give you an idea.. <?php $my_pages = array('home', 'music', 'stuffs', 'aboutus'); // check that $_GET['page'] is present, if its not we'll setup a default page if(isset($_GET['page'])) && !empty($_GET['page'])) { $requested_page = strtolower($_GET['page']); } else // $_GET['page'] not found or is empty, so we'll setup a default page to be requested { $requested_page = 'home'; } // setup an array of all your sites pages $my_pages = array('home', 'music', 'stuffs', 'aboutus'); $requested_page = strtolower($_GET['page']); // make sue the request page is in $my_Pages array if(in_array($requested_page, $my_pages)) { // the requested page will be included from a folder called my_pages in your websites root folder. // I assume the files to be included are html files include $_SERVER['DOCUMENT_ROOT'] . '/my_pages/' . $requested_page . 'html'; } else { // requested_page not found die( 'The requested page (' . $requested_page ') was not found!' ); } ?> Quote Link to comment Share on other sites More sharing options...
zavin Posted March 20, 2009 Author Share Posted March 20, 2009 A lot of useful information. Thanks for the help. 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.