Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 10 of 10
  1. #1
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default Best inclusion method?

    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 Code:
    <?php

    $page 
    $_GET['page'];

    $pages = array
            (
            
                
    'edit'    =>    './editnews.php',
                
    'post'    =>    './postnews.php'
            
            
    );
            
    if( 
    strlen$pages$page ] ) > )
    {

        require 
    $pages$page ];

    }
    else
    {

        require 
    './home.php';

    }
        
    ?>
    and Method #2 using a switch:
    PHP Code:
    <?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
    Last edited by Invent; 03-10-2007 at 02:17 PM.

  2. #2
    Join Date
    Jul 2007
    Location
    Swindon
    Posts
    990
    Tokens
    125

    Default

    i think the first way looks better personally.

  3. #3
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    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?
    Last edited by Tomm; 03-10-2007 at 03:14 PM.

  4. #4
    Join Date
    Jul 2007
    Location
    Swindon
    Posts
    990
    Tokens
    125

    Default

    Quote Originally Posted by Tomm View Post
    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.

  5. #5
    Join Date
    Dec 2006
    Posts
    521
    Tokens
    0

    Default

    If it had to be the first two, id use the switch, as its most accesible than an arrayl.

  6. #6
    Join Date
    Sep 2006
    Location
    Doncaster, UK
    Posts
    4,081
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Eccentric View Post
    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...
    Quote Originally Posted by Nain View Post
    i voted 'Not Sure' as im, not sure!

  7. #7
    Join Date
    Jul 2007
    Location
    Swindon
    Posts
    990
    Tokens
    125

    Default

    Quote Originally Posted by Aflux View Post
    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 something you need to do this actually did help me learn from tomm's comment.

  8. #8
    Join Date
    Sep 2006
    Location
    Doncaster, UK
    Posts
    4,081
    Tokens
    0

    Latest Awards:

    Default

    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.
    Quote Originally Posted by Nain View Post
    i voted 'Not Sure' as im, not sure!

  9. #9
    Join Date
    Jul 2007
    Location
    Swindon
    Posts
    990
    Tokens
    125

    Default

    that was because i didnt take that into account.

  10. #10
    ScottDiamond. Guest

    Default

    Quote Originally Posted by Aflux View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •