homepage Welcome to WebmasterWorld Guest from 54.161.246.212
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP include help
Wanna include files with parameters but...
gutabo

10+ Year Member



 
Msg#: 725 posted 9:39 pm on Mar 7, 2003 (gmt 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!

 

jatar_k

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



 
Msg#: 725 posted 9:45 pm on Mar 7, 2003 (gmt 0)

I think it will work just like you have it. Did you try it?

gutabo

10+ Year Member



 
Msg#: 725 posted 9:54 pm on Mar 7, 2003 (gmt 0)

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

Dunno why tho. Any suggestions?

olias

10+ Year Member



 
Msg#: 725 posted 9:58 pm on Mar 7, 2003 (gmt 0)

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.

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 725 posted 10:07 pm on Mar 7, 2003 (gmt 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!

Birdman

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 725 posted 10:07 pm on Mar 7, 2003 (gmt 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]

mavherick

10+ Year Member



 
Msg#: 725 posted 10:10 pm on Mar 7, 2003 (gmt 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

mapostel

10+ Year Member



 
Msg#: 725 posted 10:10 pm on Mar 7, 2003 (gmt 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.

gutabo

10+ Year Member



 
Msg#: 725 posted 10:21 pm on Mar 7, 2003 (gmt 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?

gutabo

10+ Year Member



 
Msg#: 725 posted 10:23 pm on Mar 7, 2003 (gmt 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.

;)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved