Reply to Re: includes and paths and organization

Your name:

Reply:


Posted by Erwin Moller on 09/25/07 11:31

Ron wrote:
> Hi all,
>
> Trying to work out a few problems in using php on my site. Partially
> this is a html question. I was reading a lot of the posts and it seems
> that some of the includes people are using are very complicated because
> of sessions or id's and variables I don't really know. So...
>
> Right now i use php for includes and getting some lists I make using
> mySQL and phpmyadmin and can get those out without error. For the most
> part a lot of my files were in the main directory with my index.php like
> header.php and footer.php but I just realized when I use these header
> and footer files from a different directory the paths are wrong. I was
> doing the includes like:
> <?php include("header.php"); ?> Links are good
> <?php include("../header.php"); ?> Links are bad
> <?php include("../../header.php"); ?> Links are bad
> The linked file in the header file would be at the same level as index
> but now as I have added pages I have made folders to keep things
> organized. My goal is to call my header or footer file from any level
> folder from an includes folder.
> <?php include("includes/header.php"); ?> being called from collies in
> mysite/pets/dogs or whatever.
>
> My solution is to make the link the full path with http://mysite.com and
> so on so regardless of where the header is called from the link is good.
> I always thought that relative paths are used within a site and full
> paths to link outside. My solution will work but I think there is a
> better way.
>
> So should I have my include files at the same level as my index file? or
> in a folder?
> Use full path?
> And should these include files use a .inc extension instead of php?
>
> Sorry this is a bit long for such a simple topic but I have to get
> organized. :)
>
> thx..ron
>
>

Hi Ron,

In addition to what Jerry and Lars wrote:

I prefer making one or two directories where I store my includes, and
simply add them to the include path. This makes things easy to manage.

You can use ini_set, eg:
$newIncludePath =
get_include_path().PATH_SEPARATOR.'/home/bla/public_html/includes';

ini_set("include_path",$newIncludePath);


You only need 1 file you include everywhere in all your scripts that
contains this, and you are fine.
If you ever move your directorytree, just adjust the path.

Now you can simply include everything that is stored under
/home/bla/public_html/includes, and also its subdirectories (if you name
them during your include).


Regards,
Erwin Moller

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация