Page 1 of 2
Include pages with variables in URL
Posted: Fri Nov 03, 2006 2:41 am
by MarkAshley
Hi all
I need to include a page with variables in the URL. E.g.:
This doesn't work because it tries to use the whole string 'page.php?var1=value' as the filename. Is there any way to include a page with variables in the address so the variables are GETtable?
Thanks
Mark
Posted: Fri Nov 03, 2006 3:02 am
by MarkAshley
Never mind, this won't achieve what I want it to anyway

Posted: Fri Nov 03, 2006 1:10 pm
by feyd
With included files, all variables declared before the inclusion are available to the script.
Posted: Fri Nov 03, 2006 2:14 pm
by RobertGonzalez
As an example:
Page1.php
Code: Select all
<?php
$this_var = 'Hello World!';
?>
Page2.php
Code: Select all
<?php
include 'Page1.php';
echo $this_var;
?>
Result
Posted: Fri Nov 03, 2006 2:59 pm
by Luke
actually I think a more relevant example would be:
FileOne.php
FileTwo.php
Code: Select all
<?php
$content = 'Hello World!';
include 'FileOne.php';
?>
Result:
Posted: Fri Nov 03, 2006 3:03 pm
by RobertGonzalez
Sure, if you want warnings and notices for undefined variables...

Posted: Fri Nov 03, 2006 4:52 pm
by MarkAshley
I know existing variables will be available to the included/required pages. But I wanted to include the variables with the page, so that after including 'page.php?var=123', the variable $_GET[var] would exist with a value of 123. I don't know if this is possible, but I don't need to do it any more anyway

Posted: Fri Nov 03, 2006 5:01 pm
by Burrito
I know you don't need it any more anyway but this let's assume this:
somepage.php?id=50
someotherpage.php
Posted: Fri Nov 03, 2006 5:10 pm
by Luke
Everah wrote:Sure, if you want warnings and notices for undefined variables...

well the point was that he was trying to pass a variable from the page he's working with to a page he's including...
and how do you figure there is an error or a warning? If you're on page two and you include page one... there shouldn't be any errors...

Posted: Fri Nov 03, 2006 6:44 pm
by RobertGonzalez
The Ninja Space Goat wrote:
FileOne.php
Code: Select all
<?php
// and this value is ???
echo $content;
?>
Posted: Fri Nov 03, 2006 6:46 pm
by Burrito
Everah, I think you're confused.
re-read NSG's post carefully, you'll see it wouldn't give an error or a warning.
Posted: Fri Nov 03, 2006 7:13 pm
by RobertGonzalez
Ok, I deserve to be slapped. That was udder-ly (like nipple on a cow udder-ly) stupid of me. Ok slap away... Ninja, you first, then MarkAshley, then Burrito.
/ Man I hate being stupid on a Friday afternoon. This just means all sorts of hell are going to break loose at home when I am stupid like that during the day. 
Posted: Fri Nov 03, 2006 7:40 pm
by Luke
eh... slapping probably isn't necessary...
...on the other hand... if you really want me to...
Posted: Fri Nov 03, 2006 8:30 pm
by ianhull
Code: Select all
$value1 = "SomeText";
include_once("mypage.php?var1=") . '$value1';
Posted: Fri Nov 03, 2006 8:34 pm
by feyd
The value you give to
include() can only be a file location. Nothing else.