PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
MarkAshley
Forum Commoner
Posts: 34 Joined: Fri Nov 18, 2005 1:36 am
Post
by MarkAshley » Fri Nov 03, 2006 2:41 am
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
MarkAshley
Forum Commoner
Posts: 34 Joined: Fri Nov 18, 2005 1:36 am
Post
by MarkAshley » Fri Nov 03, 2006 3:02 am
Never mind, this won't achieve what I want it to anyway
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Nov 03, 2006 1:10 pm
With included files, all variables declared before the inclusion are available to the script.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Nov 03, 2006 2:14 pm
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
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Fri Nov 03, 2006 2:59 pm
actually I think a more relevant example would be:
FileOne.php
FileTwo.php
Code: Select all
<?php
$content = 'Hello World!';
include 'FileOne.php';
?>
Result:
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Nov 03, 2006 3:03 pm
Sure, if you want warnings and notices for undefined variables...
MarkAshley
Forum Commoner
Posts: 34 Joined: Fri Nov 18, 2005 1:36 am
Post
by MarkAshley » Fri Nov 03, 2006 4:52 pm
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
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri Nov 03, 2006 5:01 pm
I know you don't need it any more anyway but this let's assume this:
somepage.php?id=50
someotherpage.php
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Fri Nov 03, 2006 5:10 pm
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...
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Nov 03, 2006 6:44 pm
The Ninja Space Goat wrote:
FileOne.php
Code: Select all
<?php
// and this value is ???
echo $content;
?>
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri Nov 03, 2006 6:46 pm
Everah, I think you're confused.
re-read NSG's post carefully, you'll see it wouldn't give an error or a warning.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Nov 03, 2006 7:13 pm
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.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Fri Nov 03, 2006 7:40 pm
eh... slapping probably isn't necessary...
...on the other hand... if you really want me to...
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Fri Nov 03, 2006 8:30 pm
Code: Select all
$value1 = "SomeText";
include_once("mypage.php?var1=") . '$value1';
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Nov 03, 2006 8:34 pm
The value you give to
include() can only be a file location. Nothing else.