Jump to content

Archived

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

brown2005

include()

Recommended Posts

i don't think you can pass URL parameters to an include, as i think the way includes work is to pull all of the files together into one long script before PHP parses it. so if index.php was:

[code]
<?php
echo $_GET['page'];
?>
[/code]

and your main.php page that includes it was:

[code]
<?php
include('index.php?page=login');
echo 'hello world';
?>
[/code]

then PHP would pull it all the bits of main.php together before parsing it:

main.php:
[code]
<?php
echo $_GET['page'];
echo 'hello world';
?>
[/code]

but as main.php has no URL vars, $_GET['page'] doesnt refer to anything. what you CAN do though, if you need to, is to set a variable before you include it. this will be automatically available to your include:

index.php:
[code]
<?php
echo $page;
?>
[/code]

main.php:
[code]
<?php
$page = "login";
include('index.php');
?>
[/code]

would make this, which would work:

main.php:
[code]
<?php
$page = "login";
echo $page;
?>
[/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.