Jump to content


Photo

include()


  • Please log in to reply
1 reply to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 24 March 2006 - 11:25 AM

can i not use

include('index.php?page=login');

as it doesnt work?

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 24 March 2006 - 12:14 PM

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:

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

and your main.php page that includes it was:

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

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

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

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:
<?php
echo $page;
?>

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

would make this, which would work:

main.php:
<?php
$page = "login";
echo $page;
?>

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users