Jump to content

Quick Question


Shaun13

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.