Exact Posted November 27, 2009 Share Posted November 27, 2009 hey guys, here is probably the simplest question you have ever seen.... sorry, im a newbie i have a index.php files that includes: footer.php header.php menu.php and home.php. where i have <?php include("home.php"); ?> , i want to be able to go to mysite.com.au/index.php?page=about etc and where home.php is i want these to appear when called about.php, contact.php, new.php, products.php. but i also want home.php to be the default page so when you go to mysite.com it appears... Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/ Share on other sites More sharing options...
premiso Posted November 27, 2009 Share Posted November 27, 2009 Look into the switch statement: switch ($_GET['page']) { default: case 'home': include('home.php'); break; case 'about': include('about.php'); break; } Hope that helps ya. Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/#findComment-966273 Share on other sites More sharing options...
Exact Posted November 27, 2009 Author Share Posted November 27, 2009 so you are saying if i have 50 different pages i have to write them down all in there? Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/#findComment-966279 Share on other sites More sharing options...
premiso Posted November 27, 2009 Share Posted November 27, 2009 You can use glob to generate a dynamic list via an array and loop through it and test/include that if you would like. $files = glob('*.php'); if (isset($_GET['page'])) { foreach ($files as $file) { if (strtolower($_GET['page']) . ".php" == $file) { include($file); } } } Un-tested but it is a rough example of what you can do. Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/#findComment-966282 Share on other sites More sharing options...
Exact Posted November 29, 2009 Author Share Posted November 29, 2009 i have been trying to get this to work all weekend.... is there anything im missing? Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/#findComment-967750 Share on other sites More sharing options...
mrMarcus Posted November 29, 2009 Share Posted November 29, 2009 ya, you're missing the part where you describe what's not working .. exactly. Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/#findComment-967763 Share on other sites More sharing options...
Exact Posted November 29, 2009 Author Share Posted November 29, 2009 hehe. sorry. the last code $files = glob('*.php');if (isset($_GET['page'])) { foreach ($files as $file) { if (strtolower($_GET['page']) . ".php" == $file) { include($file); } }} i cant get it to display home.php as default. and when you go to /index.php?page=about it is not displaying about.php Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/#findComment-967766 Share on other sites More sharing options...
mrMarcus Posted November 30, 2009 Share Posted November 30, 2009 is about.php in the same folder as index.php? if not, you need to indicate the path to the file in the include(); just add: else { include 'index.php'; } after your: if (isset($_GET['page'])) { Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/#findComment-967769 Share on other sites More sharing options...
Exact Posted November 30, 2009 Author Share Posted November 30, 2009 so if i do this it comes up blank. with no page and no error: <?php $files = glob('*.php'); if (isset($_GET['page'])) { else { include 'home.php'; } foreach ($files as $file) { if (strtolower($_GET['page']) . ".php" == $file) { include($file); } }} ?> Also yes they are all in the same folder Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/#findComment-967771 Share on other sites More sharing options...
mrMarcus Posted November 30, 2009 Share Posted November 30, 2009 sorry dude, should've been more specific: $files = glob('*.php'); if (isset($_GET['page'])) { foreach ($files as $file) { if (strtolower($_GET['page']) . ".php" == $file) { include($file); } } } else { include 'index.php'; } Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/#findComment-967776 Share on other sites More sharing options...
Exact Posted November 30, 2009 Author Share Posted November 30, 2009 ha thnks... just posting this.... this worked.... thanks heaps for your help.... ok i got it.... by using this: [code] <?php $files = glob('*.php'); if (isset($_GET['page'])) { foreach ($files as $file) { if (strtolower($_GET['page']) . ".php" == $file) { include($file); } }} else { include 'home.php'; } ?> Thanks heaps for your help! [/code] Quote Link to comment https://forums.phpfreaks.com/topic/183088-home-as-default-and-linking-in-other-pages/#findComment-967777 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.