Shaun13 Posted May 5, 2007 Share Posted May 5, 2007 On my forums, I am using a: index.php?action= type of thing. To view the forum index, it is index.php?action=index. Can someone come up with a little bit of code that makes it when someone just goes to index.php it sort of re-directs to index.php?action=index Any help is appreciated! ~Shaun Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/ Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 do you want the url to change in the browser? or just make the default action-> action=index ? if(isset($_GET['action'])){ $action = $_GET['action']; }else{ $action = 'index'; } though you must be careful with this, depending on how your includes load you should make an array of all available pages like so $page = array( 'index' => 'home.php', 'page1' => 'page1.php', 'page2' => 'page2.php'); if(isset($_GET['action'])){ $action = $_GET['action']; }else{ $action = 'index'; } if(in_array($action, $pages)){ include('INCLUDE_PATH'.$pages['$action']); }else{ echo "Page not found..."; } Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245794 Share on other sites More sharing options...
pocobueno1388 Posted May 5, 2007 Share Posted May 5, 2007 Why not put the code in the script that was originally for "index.php?action=index" show up for when they just type in "index.php"? I don't know your whole situation, but that is just a suggestion. Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245795 Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 but then it will be messy Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245801 Share on other sites More sharing options...
Shaun13 Posted May 5, 2007 Author Share Posted May 5, 2007 That might work, I will try it, thanks! Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245806 Share on other sites More sharing options...
pocobueno1388 Posted May 5, 2007 Share Posted May 5, 2007 but then it will be messy How so? Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245808 Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 u meant put the action=index pagesource in index.php, right? Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245811 Share on other sites More sharing options...
Shaun13 Posted May 5, 2007 Author Share Posted May 5, 2007 Ok, one problem. Now when I go to index.php?viewpost=1 the contents of index.php show up still. How can that be fixed? ~Shaun Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245816 Share on other sites More sharing options...
pocobueno1388 Posted May 5, 2007 Share Posted May 5, 2007 In your code you should have something like this: if (isset($_GET['viewpost'])){ //code here for the post viewing exit; // <-------You need that exit so that the rest of the code below won't show. } That "exit;" line will keep the rest of the code from below that code from showing. Just make sure you have that code above the code that will display when they go to just "index.php". Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245819 Share on other sites More sharing options...
Shaun13 Posted May 5, 2007 Author Share Posted May 5, 2007 Thanks much! ~Shaun Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245821 Share on other sites More sharing options...
pocobueno1388 Posted May 5, 2007 Share Posted May 5, 2007 u meant put the action=index pagesource in index.php, right? Right, but that is the same script. The only difference is that code would be at the bottom of the script and not in between an IF statement. So that shouldn't create a mess at all. Shaun - Your welcome =] I assume it is working now? Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245822 Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 u meant put the action=index pagesource in index.php, right? Right, but that is the same script. The only difference is that code would be at the bottom of the script and not in between an IF statement. So that shouldn't create a mess at all. Shaun - Your welcome =] I assume it is working now? i suppose, i personally like to keep my page code outside the controller, sort of a half-arsed mvc mentality plus whenever your loading other pages, you would have the overhead of that index code Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245827 Share on other sites More sharing options...
pocobueno1388 Posted May 5, 2007 Share Posted May 5, 2007 No, you don't have overhead of the index code...all you have to do is exit out of all your other code so that everything below it is ignored, which would be the index code...so it wouldn't show. Although I can see both the pros and cons of it...I am sure there are better methods, but this one works for me. Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245831 Share on other sites More sharing options...
Shaun13 Posted May 5, 2007 Author Share Posted May 5, 2007 It is working wonderfuly, thanks again. Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245833 Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 what if he wants a footer? i mean, i know it can be done, it jut seems simpler to separate your logic from your content... Link to comment https://forums.phpfreaks.com/topic/50079-quick-question/#findComment-245834 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.