PDA

View Full Version : Best inclusion method?



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 :)

Eccentric
03-10-2007, 02:18 PM
i think the first way looks better personally.

Tomm
03-10-2007, 03:12 PM
Why waste CPU cycles and memory on an array?

Just use cases. Plus why use this system when you are just including the file - whats wrong with just linking directly to the file? To me it seems you are defeating the purpose of it.

Or another suggestion: Why not use a master page handler that handles the page and transfers control over to the Application layer?

Eccentric
03-10-2007, 04:33 PM
Why waste CPU cycles and memory on an array?

Just use cases. Plus why use this system when you are just including the file - whats wrong with just linking directly to the file? To me it seems you are defeating the purpose of it.

Or another suggestion: Why not use a master page handler that handles the page and transfers control over to the Application layer?
True point which i didnt think of either.

Sygon..
05-10-2007, 11:27 PM
If it had to be the first two, id use the switch, as its most accesible than an arrayl.

Aflux
06-10-2007, 11:37 AM
True point which i didnt think of either.
Shut up, for God's sake.

You obviously know nothing about web design/development/coding or anything so just shut the hell up.

Suck-up...

Eccentric
06-10-2007, 02:27 PM
Shut up, for God's sake.

You obviously know nothing about web design/development/coding or anything so just shut the hell up.

Suck-up... you obviously don't have a life, until you do don't come insulting me. I may not be as good as anyone else but i'm learning (http://en.wikipedia.org/wiki/Learning) something you need to do this actually did help me learn from tomm's comment.

Aflux
06-10-2007, 05:59 PM
I'm not insulting you about your skills, I'm 'insulting' you about the way you post.

You post one thing, then someone else posts the truth, then you agree with them thus dis-counting your original post, hypocrite.

Eccentric
06-10-2007, 08:11 PM
that was because i didnt take that into account.

ScottDiamond.
07-10-2007, 02:30 PM
Shut up, for God's sake.

You obviously know nothing about web design/development/coding or anything so just shut the hell up.

Suck-up...

I agree fully with you adam.

No wait, I don't.

Nah I do.

Yeah shut up adam!

No I like you.

Want to hide these adverts? Register an account for free!