[thelist] Re: php include

Cardenas, Daniel daniel.cardenas at circle.com
Wed Jan 22 22:00:01 CST 2003


On 03.01.22 15.11, "Russell Griechen" <russgri at bellsouth.net> wrote:

> Thanks Daniel and Martyn
> Narrowing the focus:
> I have the file:
> head.inc or head.php or head.inc.php  //which should I save it as.

I don't think it matters- I think you can use .foo if you'd like...
I use .inc or .txt, but .php should be fine too, although any php code in a
file ending in .php would be executable. Could be a bad thing (passwords
etc.)


> and further...
> Current Directory:/home/russgri/www/head.inc    //I assume
> next we have:
> <?php
> include('!paths.inc');
> include($includesDir . 'fileHead.inc'); // writes file head using 1st 3 vars
> ?>
> // I assume:
> File/Save As/home/russgri/include/path.inc  // to allow global rather than
> relative urls
>
> or Current Directory:/home/russgri/www/include // to allow relative urls
>
> // Then to call footer:
> <? include($includesDir . 'pageFooter.inc');?>
> // I would then edit the path.inc file to reflect the added footer.inc url:
> <?php
> include('!paths.inc');
> include($includesDir . 'fileHead.inc'); // writes file head using 1st 3 vars
> include($includesDir . 'fileFooter.inc');  //writes file footer using last
> var
> ?>
> Thanks in advance for walking me thru this.
>


I think you got it. Include "paths.inc" into every file. The file
"paths.inc" contains variables each containing the path to a directory,
relative to the directory that particular "paths.inc" file is in.

For example, I have a paths.inc file in the root directory that has these
variables:
$includesDir = 'includes/';
$cssDir = 'css/';
$jsDir = 'js/';

I also have one in a "photos" subdirectory that has these variables:
$includesDir = '../includes/';
$cssDir = '../css/';
$jsDir = '../js/';

That way the relative paths to several directories can be written to any
file anywhere in my site's hierarchy.

So, if you want to include "fileFooter.inc" in all your pages in your site,

1. Create an includes directory somewhere in your site that contains the
file: "fileFooter.inc"

2. put a "paths.inc" file into all your subdirectories

3. edit the paths.inc file in each subdirectory so that it contains a
variable ($includesDir) that contains the url to "fileFooter.inc" relative
to that particular directory

4. include a "paths.inc" call in your files

5. include a "fileFooter.inc" call in your files


Hope that makes sense.



> Russell Griechen.//Daniels relevant example template is below.
> <?php
> $title ='home'; // title of this page, passed to fileHead.inc
> $css  = array('stylesheet01.css','stylesheet02.css'); // writes css file(s)
> include('!paths.inc'); // file that contains vars that contain paths
> relative to this file
> include($includesDir . 'fileHead.inc'); // writes file head using 1st 3 vars
> ?>
>
> <body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
>
> <!-- PAGE HEAD -->
> <? include($includesDir . 'pageHead.inc');?> // writes page head content
>
> <!-- PAGE BODY -->
> <div id="bodyDiv">
> ## body content ##  <!-- includes static and dynamic content -->
> </div>
>
> <!-- PAGE FOOTER -->
> <? include($includesDir . 'pageFooter.inc');?> // writes page footer
>
> </body>
> </html>
>




More information about the thelist mailing list