sending params to include/require

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
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

sending params to include/require

Post 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?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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'];
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

anjanesh's solution requires URL wrappers to be on.

before the include, you could just set a special variable for it instead.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post 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.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

URL wrappers is on in most hosts
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
User avatar
pelegk2
Forum Regular
Posts: 633
Joined: Thu Nov 27, 2003 5:02 am
Location: Israel - the best place to live in after heaven
Contact:

how can i check

Post by pelegk2 »

how can i check :
URL wrappers is on in most hosts
???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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:
Post Reply