Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.