Invent
03-10-2007, 02:05 PM
Hey,
I'm trying to think of the best way to include my files in a new script I'm making. I know this is very petty deciding between one of these; but I'm wondering which one would be more efficient (if one can be).
So yeah, here is Method #1 using an Array.
<?php
$page = $_GET['page'];
$pages = array
(
'edit' => './editnews.php',
'post' => './postnews.php'
);
if( strlen( $pages[ $page ] ) > 0 )
{
require $pages[ $page ];
}
else
{
require './home.php';
}
?>
and Method #2 using a switch:
<?php
switch ($_GET["page"])
{
case "postnews":
include("postnews.php");
break;
#####
case "editnws":
include("editnws.php");
break;
#####
default:
include("home.php");
break;
}
?>
Thanks!
P.S: I don't want to use a inclusion script like one that just gets the file from a $_GET, checks if it exists and if it does, shows it. As that could be a potential security risk. I prefer defining the files that can be used :)
I'm trying to think of the best way to include my files in a new script I'm making. I know this is very petty deciding between one of these; but I'm wondering which one would be more efficient (if one can be).
So yeah, here is Method #1 using an Array.
<?php
$page = $_GET['page'];
$pages = array
(
'edit' => './editnews.php',
'post' => './postnews.php'
);
if( strlen( $pages[ $page ] ) > 0 )
{
require $pages[ $page ];
}
else
{
require './home.php';
}
?>
and Method #2 using a switch:
<?php
switch ($_GET["page"])
{
case "postnews":
include("postnews.php");
break;
#####
case "editnws":
include("editnws.php");
break;
#####
default:
include("home.php");
break;
}
?>
Thanks!
P.S: I don't want to use a inclusion script like one that just gets the file from a $_GET, checks if it exists and if it does, shows it. As that could be a potential security risk. I prefer defining the files that can be used :)