Jump to content


Photo

simple include problem


  • Please log in to reply
4 replies to this topic

#1 ayaycaptainchris

ayaycaptainchris
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 20 June 2006 - 06:22 AM

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

#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 20 June 2006 - 06:51 AM

require() or require_once()
try it, hope I get what you mean.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 June 2006 - 10:11 AM

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.

#4 ayaycaptainchris

ayaycaptainchris
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 20 June 2006 - 02:21 PM

[!--quoteo(post=385930:date=Jun 20 2006, 05:11 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 20 2006, 05:11 AM) View Post[/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.



#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 June 2006 - 02:40 PM

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:
if(isset($_GET['do']))
{
    switch($_GET['do'])
    {
        case 'test':
            include 'include_test.php';
            break;

        case 'test2':
            include 'include_test2.php';
            break;
    }
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users