Welcome to WebmasterWorld Guest from 54.196.244.186

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP include help

Wanna include files with parameters but...

     
9:39 pm on Mar 7, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 17, 2001
posts:126
votes: 0


Hi again!

I would like to know if is there a way to parse some parameters in the include function, something like

$filename="foo";
$fileclass="bar";

include ($filename.".php?id=".$fileclass);

Can this be done? How?

Thanks in advance!

9:45 pm on Mar 7, 2003 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


I think it will work just like you have it. Did you try it?
9:54 pm on Mar 7, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 17, 2001
posts:126
votes: 0


Yeah, it doesn't work... :(

Dunno why tho. Any suggestions?

9:58 pm on Mar 7, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Mar 3, 2001
posts:367
votes: 3


That wouldn't work in ASP as the includes are all included before anything in the script is processed, so it wont pick up the variables. Don't know if it works the same in PHP though, will be interested to see the answer.
10:07 pm on Mar 7, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Check to make sure the variables are set by printing them.

$filename="foo";
$fileclass="bar";
$include = $filename$fileclass
print $include;

If the url looks good, change the last line to:

include ($include);

Also bookmark the PHP [php.net] manual. It's very useful!

10:07 pm on Mar 7, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Check to make sure the variables are set by printing them.

$filename="foo";
$fileclass="bar";
$include = $filename$fileclass
print $include;

If the url looks good, change the last line to:

include [php.net] ($include);

Also bookmark the PHP [php.net] manual. It's very useful!

OOOPS!

[edited by: Birdman at 10:11 pm (utc) on Mar. 7, 2003]

10:10 pm on Mar 7, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:June 3, 2002
posts:169
votes: 0


It shouldn't work for the reasons olias pointed out. I'm not exactly sure what you're trying to do, but you could

a) use the $fileclass in the included file (included file inherit the scope where they're included)
or
b) just before your include, set $id = $fileclass (that won't work if you're retrieving the id var through $_GET[] though)

mavherick

10:10 pm on Mar 7, 2003 (gmt 0)

New User

10+ Year Member

joined:Feb 23, 2003
posts:27
votes: 0


Hi gutabo,

All variables from your main script are also available to included files. Basically the include() fucntion just "pastes" the specified file into the source code before it gets executed. Therefore they can access the same variables as the main script.

10:21 pm on Mar 7, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 17, 2001
posts:126
votes: 0


Thanks for the fast, effective replies!

Ok, I found out that it works IF I don't use the "?id=" part...

Any other suggestions?

10:23 pm on Mar 7, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 17, 2001
posts:126
votes: 0


Ok, ok, I just actually _processed_ the data from the previous post(my brain's PHP version is old, you know... I must be really tired) so there's no need for the "?id=" part...

THANK YOU. tHi5 BOARD r0xx0rz j00r b0xx0rz.

;)