Page 1 of 1

help using 'include'

Posted: Thu Jun 30, 2005 2:52 pm
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.

Posted: Thu Jun 30, 2005 2:55 pm
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');

Posted: Thu Jun 30, 2005 2:56 pm
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...

Posted: Thu Jun 30, 2005 2:57 pm
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
}

?>

Posted: Thu Jun 30, 2005 9:10 pm
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?

Posted: Thu Jun 30, 2005 11:32 pm
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'];