Forum Moderators: coopster

Message Too Old, No Replies

Virtual Includes

Moving from ASP to PHP

         

Ben_Neake

11:41 am on Apr 10, 2006 (gmt 0)

10+ Year Member



Hi. I am in the process of learning PHP - having used ASP for the past 7 years. So far I'm finding it to be very user-friendly. However there's one issue I can't quite get my head around: includes.

In ASP, I would normally set up a site-specific includes folder in the site root, and use the following code:

<!--#include virtual="/includes/header.asp"-->

However, from what I gather, PHP requires that you set assign the path of your include folder to you include_path parameter in the php.ini

I've since learned that you assign multiple paths to this parameter.

However we host many sites on our server, and they will very likely all have includes named "header.php" and "footer.php" etc. So my question is can you tie a particular include_path to a particular site - or do I have to give all my includes unique names?

Many thanks in advance.

Ben

coopster

12:25 pm on Apr 10, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Ben_Neake.

includes work much the same. You can set the include path specific to the site or to the server. You can tell PHP exactly where to find it or allow it to use the path in the php.ini directive. In this particular instance to include common HTML like that, one of the more common methods is to tell PHP right where it is, but use the DOCUMENT_ROOT to set the static path on the fly based on the site that is calling it.

<?php include [php.net] $_SERVER [php.net]['DOCUMENT_ROOT'] . '/includes/header.php';?>

omoutop

12:45 pm on Apr 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



can the virtual() function help? It has similar syntax with <!--#include virtual="/includes/header.asp"-->

Ben_Neake

2:39 pm on Apr 10, 2006 (gmt 0)

10+ Year Member



Many thanks guys -that seems to answer my question.

And now I have another one:

Is there an equivalent to Datashaping in PHP? I've scoured the internet, but as yet no joy. Probably because I am using the wrong terminology...
:)

Ben