Welcome to WebmasterWorld Guest from 54.226.143.14

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)

10+ Year Member



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)

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



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

10+ Year Member



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

Dunno why tho. Any suggestions?

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

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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)

10+ Year Member



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)

10+ Year Member



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)

10+ Year Member



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)

10+ Year Member



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.

;)

 

Featured Threads

Hot Threads This Week

Hot Threads This Month