Jeigh Posted July 12, 2008 Share Posted July 12, 2008 I was reading this tutorial http://www.phpfreaks.com/blog/mod-rewrite-ignore-dir on PHPFreaks and read the following at the start of the tutorial: "So i have my little website and like a lot of websites, I have one index page that I simply pass a parameter through a GET request and that determines the output of the site." All websites I've made I just have each feature of the site in a different php file, for example I'll just have addresses like: www.example.com/register.php www.example.com/uploadsomthing.php www.example.com/showsomthing.php?id=1 I'm making a new site now and want everything to be as professional as it can be, and to me this always seems very messy and unprofessional. So my question is what exactly is that quote talking about and how is it achieved. I'm assuming it will involve somthing like: if($_GET['p'] == "register"){ (HTML + PHP for register here } else if($_GET['p'] == "upload"){ (HTML + PHP for uploading page here) } and the addresses will be www.example.com/index.php?p=register or /index.php?p=upload etc. I also assume having it set up like this would make using mod_rewrite much easier (which I also plan to do). So before start jumping in and doing stuff I want to make sure what I'm assuming is correct or if not how exactly do I go about doing it. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/114391-solved-passing-requests-to-index-page/ Share on other sites More sharing options...
Ken2k7 Posted July 12, 2008 Share Posted July 12, 2008 Yeah, you can do that, but that just means the index page will get a lot of data passed to it. By the way, that method isn't the best solution. It'll make the index page a b*tch to code. Link to comment https://forums.phpfreaks.com/topic/114391-solved-passing-requests-to-index-page/#findComment-588244 Share on other sites More sharing options...
Jeigh Posted July 12, 2008 Author Share Posted July 12, 2008 Ah, Is there a certain way of doing this that is generally accepted as being the most 'professional' or effecient? Link to comment https://forums.phpfreaks.com/topic/114391-solved-passing-requests-to-index-page/#findComment-588245 Share on other sites More sharing options...
papaface Posted July 12, 2008 Share Posted July 12, 2008 Yeah, you can do that, but that just means the index page will get a lot of data passed to it. By the way, that method isn't the best solution. It'll make the index page a b*tch to code. Not necessarily if you code it correctly. I would do something like: Index.php: <?php if (strlen($_GET['p']) > 0) { switch($_GET['p']) { case "register": include("register.php"); break; case "login": include ("login.php"); break; default: include ("indexpage.php"); } } else { include ("indexpage.php"); } ?> Pretty simple in my opinion. Just code the pages separately but include them as one page using switch and NOT if statements. Link to comment https://forums.phpfreaks.com/topic/114391-solved-passing-requests-to-index-page/#findComment-588251 Share on other sites More sharing options...
himegoto Posted July 12, 2008 Share Posted July 12, 2008 Yeah, you can do that, but that just means the index page will get a lot of data passed to it. By the way, that method isn't the best solution. It'll make the index page a b*tch to code. When I want to base everything off index.php I use this: http://www.somerandomsite.com/index.php?page=whatever <?php require_once("includes/header.php"); if (isset($_GET['mode'])){ $page_sel = strtolower($_GET['page']) . ".php"; } else { $page_sel = "default.php"; } if (is_file($page_sel)){ include ($page_sel); } else { include ("default.php"); } include("includes/footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/114391-solved-passing-requests-to-index-page/#findComment-588253 Share on other sites More sharing options...
Jeigh Posted July 12, 2008 Author Share Posted July 12, 2008 Thanks for the responses, I will probably use somthing like what papaface posted. Seems neat and fairly simple to do. Link to comment https://forums.phpfreaks.com/topic/114391-solved-passing-requests-to-index-page/#findComment-588265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.