Jump to content

Archived

This topic is now archived and is closed to further replies.

ayaycaptainchris

simple include problem

Recommended Posts

I got this really huge file (lets say its called index.php).

i i decided to cut it into chunks.

basically. im wondering with this code

<?php


if($_GET['do']=="test"){
include ("include_test.php");

if($_GET['do']=="test2"){
include ("include_test2.php");
}

?>

if i just access index.php, it will only load index.php.

my question is...will it also load include_test.php and include_test2.php and just NOT show it?
or...obviously with the if statement, it will only include include_test.php if do=test.

i know my question is simple, but i needa make sure. i needa reduce my bandwidth usage and i think this one is a simple solution

i cut the original file from 450 kb to now only 35 but it has a lot of includes. i need to know if it loads the includes and just not show it (hence bandwidth is not really reduce) or it only loads it only if the IF statement is true. thank you. i hope youunderstood my question

Share this post


Link to post
Share on other sites
require() or require_once()
try it, hope I get what you mean.

Share this post


Link to post
Share on other sites
If your file is 450Kb it wont be taking any bandwidth as it isnt acutlly sending that 450Kb file to the client. The thing that uses the bandwidth is the ouput, For example if you had a php script which is 1MB in size and all it did was return a simple hello world message which will come to less than 1K. It'll only take 1K out of your alloted bandwidth.

The only problem that will happen is the amount of time it'll take PHP to parse the 1MB file.

Share this post


Link to post
Share on other sites
[!--quoteo(post=385930:date=Jun 20 2006, 05:11 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 20 2006, 05:11 AM) [snapback]385930[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If your file is 450Kb it wont be taking any bandwidth as it isnt acutlly sending that 450Kb file to the client. The thing that uses the bandwidth is the ouput, For example if you had a php script which is 1MB in size and all it did was return a simple hello world message which will come to less than 1K. It'll only take 1K out of your alloted bandwidth.

The only problem that will happen is the amount of time it'll take PHP to parse the 1MB file.
[/quote]

thank you!

but still, there are functions that only work on some of the DO= something pages and its loading everytime the that page is accessed. i made it require a function_test.php file with an IF statement.

thank you for your reply.

i still need answer to my question though.

Share this post


Link to post
Share on other sites
Abouty your question. PHP will not include include_test.php or include_test2.php by defualt, Unless 'do' is set to either 'test' or 'test2' in the address bar. As thats what the if statment does. it will only execute what is between the curly braces {} if the condition is true.

Also you might want to look into switch/case statements:
[code]if(isset($_GET['do']))
{
    switch($_GET['do'])
    {
        case 'test':
            include 'include_test.php';
            break;

        case 'test2':
            include 'include_test2.php';
            break;
    }
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.