jptristam Posted February 1, 2009 Share Posted February 1, 2009 I don't really know how to word this, but here we go. I want to have a PHP include on one page, so I can have ONE homepage as a template. So when I type in http://url.com/index.php?page=about.html it brings me to about. But I also want the script to get index.php?page=news.html defaulty. So if I go to http://url.com it goes to index.php?page=news.html, but when I click any other other link it goes there. Kind of a rough explanation, but any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/143328-solved-include-help/ Share on other sites More sharing options...
jptristam Posted February 1, 2009 Author Share Posted February 1, 2009 Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751733 Share on other sites More sharing options...
Philip Posted February 1, 2009 Share Posted February 1, 2009 if(!$_GET['page']) $pageToInclude = 'news.html'; Quote Link to comment https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751734 Share on other sites More sharing options...
jptristam Posted February 1, 2009 Author Share Posted February 1, 2009 When I put that into the index.php file, it did nothing. I put <?php if(!$_GET['page']) $pageToInclude = 'asdf.html'; ?>. What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751739 Share on other sites More sharing options...
Philip Posted February 1, 2009 Share Posted February 1, 2009 Well, that was just an example. Post your code that you're using now, and 'll try my best to explain how to integrate it & possibly improve your current code. Quote Link to comment https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751744 Share on other sites More sharing options...
jptristam Posted February 1, 2009 Author Share Posted February 1, 2009 This is all I got... I want it to go to "index.php?page=main.html" when I go to jptristam.net. Then from there I want to be able to click a link, say about, and go to index.php?page=about.html. I have no PHP currently, I deleted it cause it did not work. Quote Link to comment https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751747 Share on other sites More sharing options...
Philip Posted February 1, 2009 Share Posted February 1, 2009 Okay, we're going to use GET variables, which are the ones in the url. So, if I visit foo.com/bar.php?var=value, I can do the following: <?php echo $_GET['var']; // this will show "value" ?> So, in your case we can do a few things... a switch statement or use arrays I'd recommend going with arrays, as it's the easiest to update.... let me get you some code real quick. If you have access to the server, play around with trying the code above Quote Link to comment https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751752 Share on other sites More sharing options...
jptristam Posted February 1, 2009 Author Share Posted February 1, 2009 I used a conditional statement and got it to work. Thanks anyways! Quote Link to comment https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751753 Share on other sites More sharing options...
Philip Posted February 1, 2009 Share Posted February 1, 2009 <?php // get the URL variable $pageVar = $_GET['page']; // create an array of acceptable pages the user can load: $acceptable = array('main', 'about', 'news', 'contact'); // let's check to see if the variable in the url is in the array or not: if(!empty($pageVar) && in_array($pageVar, $acceptable)) { // load the page } else { // that page is invalid! // we can show an error page, or redirect the to the // default page } ?> I'm not sure how you want to include the pages, but that's the basic syntax Quote Link to comment https://forums.phpfreaks.com/topic/143328-solved-include-help/#findComment-751754 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.