tags:

views:

42

answers:

2

I am using this PHP code:

 if (isset($_GET['c'])) {

    $pages = array("home", "upload", "signup");

    if (in_array(strtolower($_GET['c']), $pages)) 
        include('pages/'.$_GET['c'].'.php'); 
    else echo "Page not found =(";

}

How should I do to so that the default page will be home.php with this code?

+1  A: 

Assuming you still want a "Page not found" error when the visitor specifies an invalid page, you could do it like this:

if (isset($_GET['c'])) {
    if (in_array(strtolower($_GET['c']), $pages)) 
        include('pages/'.$_GET['c'].'.php'); 
    else echo "Page not found =(";
} else {
    include('pages/home.php');
}
VoteyDisciple
+1  A: 

What about something like this :

$page = 'home';
if (isset($_GET['c'])) {
    $pages = array("home", "upload", "signup");
    if (in_array(strtolower($_GET['c']), $pages))  {
        $page = strtolower($_GET['c'])
    }
}

include('pages/' . $page . '.php');

BTW : by "default" I understood "if page not found, then include default one"


Also : if you files names are lower-case, you should use the lowercase name when including -- you are already useing lowercase for the comparison, so why not for the include ?

If you are developping on a Windows environment, files names are not case-sensitive, but the are on Linux -- and if you deploy on a Linux server... I let you guess what could happen ;-)

Pascal MARTIN