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 Quote Link to comment 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..."; } Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 but then it will be messy Quote Link to comment 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! Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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". Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 5, 2007 Author Share Posted May 5, 2007 Thanks much! ~Shaun Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Shaun13 Posted May 5, 2007 Author Share Posted May 5, 2007 It is working wonderfuly, thanks again. Quote Link to comment 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... 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.