Page 1 of 1

sending params to include/require

Posted: Fri Jul 02, 2004 4:42 am
by pelegk2
why can i use include or require like this :

Code: Select all

<?php
require("inc/ock.php?x=3");
or
include("inc/ock.php?x=3");

?>
must i make before this a var $x?

Posted: Fri Jul 02, 2004 7:10 am
by anjanesh
This works fine when its on the www when given like include("http://mysite.com/includefile.php?x=56"). It doesn't seem to work in localhost.
Check out : http://in2.php.net/manual/en/function.include.php
It mentioned there too.

This works though :

a.php
=====

Code: Select all

<?php
include("http://localhost/test/b.php?x=5");
?>
b.php
=====

Code: Select all

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

Posted: Fri Jul 02, 2004 10:39 am
by feyd
anjanesh's solution requires URL wrappers to be on.

before the include, you could just set a special variable for it instead.

Posted: Fri Jul 02, 2004 10:47 am
by scorphus
pelegk2, anjanesh's solution works in some cases. But if you want the included PHP page to do something for the including one, you will have to do it another way.

The PHP Manual is always a great resource:
The section '[url=http://www.php.net/include#AEN4518]Example 11-3. Basic include() example[/url]' of the [url=http://www.php.net/include]include()[/url] function reference wrote:vars.php

Code: Select all

<?php

$color = 'green';
$fruit = 'apple';

?>
test.php

Code: Select all

<?php

echo "A $color $fruit"; // A

include 'vars.php';

echo "A $color $fruit"; // A green apple

?>
Regards,
Scorphus.

Posted: Fri Jul 02, 2004 11:18 am
by anjanesh
URL wrappers is on in most hosts

Posted: Fri Jul 02, 2004 11:27 am
by redmonkey
I'm failing to see the point of why you want to use URL wrappers to access a file on your own machine?

I don't see the problem of assigning the variable first prior to the include.

If you want the parsed output of the included file use eval.

Posted: Fri Jul 02, 2004 11:49 am
by redmonkey
Just to clarify, if you just need the contents of the file displayed inline at the point your script calls the include, then just assign the variable x and include the file.

If you need to grab the contents of the parsed file into a variable or such then you can either read the contents of the source file in to a variable, start a new output buffer eval the variable (which contains the source) then assign the contents of the output buffer to a variable, then clean the output buffer.

Or, simply start an new output buffer, include the file, then assign it to a variable, then clean the output buffer.

how can i check

Posted: Sun Jul 04, 2004 2:34 am
by pelegk2
how can i check :
URL wrappers is on in most hosts
???

Posted: Sun Jul 04, 2004 9:47 am
by feyd
phpinfo().. Don't bother, it'd be a waste of processing cycles to use it, compared to just setting the variable. Plus your server may not support remote includes... :roll: