Jump to content

include()


brown2005

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]
Link to comment
https://forums.phpfreaks.com/topic/5677-include/#findComment-20239
Share on other sites

Archived

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

×
×
  • Create New...

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.