[thelist] php include

Cardenas, Daniel daniel.cardenas at circle.com
Thu Jan 30 12:07:02 CST 2003


On 03.01.29 20.10, "Russell Griechen" <russgri at bellsouth.net> wrote:

[snip]

> // filling in the syntax: I have a folder named   'include'  in /home/user/
> include  where
> www= /home/user/www

Sorry, I'm not following you there...

> // here is the content of  'paths.inc' which resides in the 'include' folder
> along with 'head.inc' and 'footer.inc'

The way I use 'paths.inc' is to place it in the directory on the same level
as whatever file I'll be calling it from, and in it are the relative paths
to everything else. So instead of putting it in the includes directry, I put
it in the document root and call it to define the path to the includes
directory, as well as the js dir, the css dir, the site root, etc.

> <?php
> global $IncludePath;
> $IncludePath = sportsmenafield.com-www($DOCUMENT_ROOT) . "/include/";
> include('!paths.inc');
> include($includePath . 'fileHead.inc');
> include($includePath . 'fileFooter.inc');

You have paths.inc calling files it doesn't need (including itself)
These three are all it needs:

> $includesDir = 'includes/';
> $cssDir = 'css/';
> $jsDir = 'js/';

> ?>
> So how am I doing?
> code shown at http://sportsmenafield.com/index.txt
> I called this code at:
> page shown at http://sportsmenafield.com/index.php
> Error message:
> Parse error: parse error in /home/russgri/sportsmenafield-www/index.php on
> line 6
>
> Russell Griechen
>
>
>

Here's an example of my site structure and how the files come together:

 myRoot.net/
  css/
    stylesheet01.css
    stylesheet02.css
  images/
    image01.gif
    image02.gif
  includes/
    fileHead.inc       //  [1]
    pageFooter.inc     //  [2]
    pageHead.inc       //  [3]
  index.php            //  [4]
  js/
    script01.js
    script02.js
  paths.inc            //  [5]


===================================================================
[1]  fileHead.inc
===================================================================

<html>
<head>
<title>myRoot.net | <?php echo($title);?></title>
<?php
for ($i=0; $i<count($css); $i++) {// loop through $css array
  echo("<link href=\"$cssDir$css[$i]\" ##TRUNCATED CSS LINK## >\n");
}
for ($i=0; $i<count($js); $i++) {// loop through $js array
  echo("<script src=\"$jsDir$js[$i]\" ##TRUNCATED SCRIPT TAG##>\n");
}
?>
</head>


===================================================================
[2]  pageFooter.inc
===================================================================

<div id="footerDiv">
## FOOTER CONTENT ##
</div>


===================================================================
[3]  pageHead.inc
===================================================================

<div id="headerDiv">
## HEADER CONTENT ##
</div>


===================================================================
[4]  index.php
===================================================================

<?php

/* -------------------------------------------------------------------
   first 3 vars called by fileHead.inc
------------------------------------------------------------------- */
   // title of this page:
   $title='home';

   // js file(s) to write:
   $js  = array('script01.js','script02.js');

   // css file(s) to write:
   $css  = array('stylesheet01.css','stylesheet02.css');


/* -------------------------------------------------------------------
   paths.inc contains variables that contain paths relative to this
   file, ie: $jsDir = 'js/';  $cssDir = 'css/'; etc.
   most importantly it defines the variable $includesDir -
   as that var is used immediately afterwards
------------------------------------------------------------------- */
   include('paths.inc');


/* -------------------------------------------------------------------
   this line calls fileHead.inc, which writes everything from "<html>"
   to "</head>" - fileHead.inc calls the first three vars named up top
------------------------------------------------------------------- */
   include($includesDir . 'fileHead.inc');

?>

<body>

<!-- PAGE HEAD -->
<?php
/* -------------------------------------------------------------------
   this line calls pageHead.inc, which writes "page" header content -
   (nav, logotype, breadcrumbing, date, etc.)
   not to be confused with fileHead.inc which writes "file" head
   content (<html><head><title></title><link /></head>)
------------------------------------------------------------------- */
include($includesDir . 'pageHead.inc');
?>

<!-- PAGE BODY -->
<div id="bodyDiv">
## BODY CONTENT ##
</div>

<!-- PAGE FOOTER -->
<?php
/* -------------------------------------------------------------------
   this line calls pageFooter.inc, which writes "page" footer content
   (copyright, contact links, etc.)
------------------------------------------------------------------- */
include($includesDir . 'pageFooter.inc');
?>

</body>
</html>



===================================================================
[5]  paths.inc
===================================================================

<?php
$baseDir = '';                // root directory
$includesDir = 'includes/';   // includes directory
$cssDir = 'css/';             // css directory
$jsDir = 'js/';               // js directory
?>




Hope that helps

-dc










More information about the thelist mailing list