Forum Moderators: coopster
What I want to do is have those things load into ./home/index.php - like a template. The problem is the files in those directories require/include their own files and need their own sub-directories to function properly.
So, the question is: How do I arrange and code my site so that everything loads into the index.php template without problems?
Thanks in advance.
- fresh
Remember that when including files the paths must work from the file which is including them. If you use root relative includes you should be fine. Then no matter where on the site the template is included you paths are correct.
you could also use $_SERVER['DOCUMENT_ROOT'] [php.net] with your includes, if needed, to reference the root of the site.
'DOCUMENT_ROOT'
The document root directory under which the current script is executing, as defined in the server's configuration file.
/home/username/mysite.com-www
$_SERVER['DOCUMENT_ROOT']
//and my include folder was "includes"
<?php
include($includesDir . 'pageFooter.inc.php');
?>
How would I weave this all together?
See the documentation for the auto_prepend_file [php.net] and auto_append_file [php.net] directive.
Andreas
will include pageFooter.inc.PHP using an absolute path.
-------
//Question.
$IncludesDir is has to be defined in a file called paths.inc with the following line...
$includesDir = 'includes/'; // includes directory
and if so is the above line correct including slashes, punctuation etc?
?is paths.inc or indeed config.php global control pages or would any other name suffice?
or...
If a page contains:
$includesDir = 'includes/';
or a similar variable...does that make it the control mechanism regardless of the name?
but that file would still have to be included. ;)
$includesDir = 'includes/'; // includes directory
but
The include() [php.net] statement includes and evaluates the specified file.
just stating that because I don't quite understand the direction of the thought. Better might be
$includesDir = $_SERVER['DOCUMENT_ROOT'] . 'includes/';
does that make it the control mechanism regardless of the name?
It can. If all of your included files are in that directory you could use that for including files. Again, I don't totally understand what you are asking specifically.
<sidenote>Have you ever tried typing the path to a file with a .inc extension into your browser? It shows the code. My personal preference is not to show anyone what I am doing on the server side. .inc.php or just .php would be preferable to keep server side code on the server side. (personal paranoia ;))
This is a simple and elegant post and it nailed the question.
However: ...correct me if I am wrong...
I still have to define the name of the include folder or type the name of the folder in each include
So... I still have to create a file names..
paths.inc and place it in the root folder.
and in it jatar offered this solution:
$includesDir = $_SERVER['DOCUMENT_ROOT'] . 'includes/';
----
and in index.php I will need to include it thus:
<?PHP
include($_SERVER['DOCUMENT_ROOT' . $includesDir . 'paths.inc.');
?>
Please comment.