Forum Moderators: coopster

Message Too Old, No Replies

another PHP include problem

include using variables

         

webfoo

3:00 pm on May 23, 2008 (gmt 0)

10+ Year Member



In the development of a primitive CMS:


<?php
$pgstr='"' . $page . '.inc"';
echo $pgstr;
include($pgstr);
?>

The $page variable is REQUESTed from the URL. The code block above is supposed create a string, and then include that string.

About the string - if $page="Contact" the string needs to be "Contact.inc".

It's not working. No error messages, the rest of the page executes fine. It just seems to ignore the include line.

I put the echo $pgstr; in to test that it formed the string properly - that does work.

Any suggestions?

russkern

3:31 pm on May 23, 2008 (gmt 0)

10+ Year Member



Try forming your include file this way:

include('./'.$pgstr);

webfoo

3:46 pm on May 23, 2008 (gmt 0)

10+ Year Member



Nope, that didn't work.

However, the problem is solved! I went at it from the other angle and just did

include($page);

and then removed the .inc extension from each file. That works!

Thanks.

coopster

1:08 am on May 24, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It looks like you were attempting to include a string rather than a filename.
include $page . '.inc';

That probably would have worked.