help using 'include'

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

Post Reply
MasterCephus
Forum Newbie
Posts: 3
Joined: Thu Jun 30, 2005 2:49 pm

help using 'include'

Post by MasterCephus »

I am trying to use an include function in my code, but I keep getting an error.

The problem is that I need to also send a URL wrapper.

For instance, the file is 'code.php', but I need it to be invoked as 'code.php?arg=x'

Is there anyway to do this?

I tried to follow the example from here, but it doesn't seem to work.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

include() is a filesystem level function.

Those query strings are only parsed when read via a web server so include ('http://localhost/~username/file.php?page=blah');
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you can't do that, you'll either have to just use the url params on the parent page, or set some right before you include the page...
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

guess, browser called file is:

index.php?arg_x=whatever


index.php:

Code: Select all

<?php
include('test.inc.php');
?>
test.inc.php:

Code: Select all

<?php
if (isset($_GET['arg_x'])) { $arg_x=$_GET['arg_x']; } // You may put this and the next line ...
else { $arg_x=''; } // ... into file index.php also.

if ($arg_x=='whatever')
{
  //do something
}
else
{
  // do something else
}

?>
MasterCephus
Forum Newbie
Posts: 3
Joined: Thu Jun 30, 2005 2:49 pm

Post by MasterCephus »

Well, if I can only use the 'include("code.php")'

Is there a way I can send a variable to that page? like send it a $variable?

and if the variable is "" do something and if it's "x" do something else?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

do what I told you to do.

you can either use the $_GET[] array that is passed from the url or you can set your own above the include:

ex:

Code: Select all

$_GET&#1111;'whatever'] = &quote;bob&quote;;
include(&quote;yourpage.php&quote;);

Code: Select all

echo $_GET&#1111;'whatever'];
Post Reply