tags:

views:

57

answers:

2

Anyone knows how Invision Power Board makes their urls like the following?

index.php?showuser=349
index.php?showtopic=83
index.php?showforum=9

and just pages:
index.php?act=register
index.php?act=about

and so on. How they do it? I'm sure they don't do it like i do now:

if (isset($_GET['showtopic'])){
include('viewtopic.php');
else if (isset($_GET['showuser'])){
include('viewuser.php');
}

else if (isset($_GET['act']) && $_GET['act'] == 'register'){
include('register.php');
} 

else if (isset($_GET['act']) && $_GET['act'] == 'about'){
include('about.php');
}
else 
{
echo "page not found.";
}
+1  A: 

To do the "act=" thing you don't need a huge chain of if statements. You could do it like this, for example:

$pages = array('register', 'about', ...);

if (in_array($_GET['act'], $pages)) {
    include $_GET['act'].'.php';
} else {
    // display an error
}
yjerem
+1  A: 

Maybe you could add it to an array.

$pages = array('showtopic', 'showuser');

foreach ($pages as $page) {
if (intval($_GET[$page])) {
include("$page.php");
}
}
Digerdoden