Reply to Re: includes and paths and organization

Your name:

Reply:


Posted by Jerry Stuckle on 09/25/07 10:49

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.
>

Yes, this happens when you use relative paths.

> 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.
>

A terrible way to do it. It makes another request to the server,
increasing network traffic and server load. You won't be able to
include anything other than HTML, because any PHP code will be parsed
before you get the page. And you won't be able to hide it in a private
directory, inaccessible other than through your other pages.

> 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
>
>
>
>

Use absolute paths. $_SERVER['DOCUMENT_ROOT'] gives you the absolute
path to your website's root directory.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[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

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