Reply to Re: includes and paths and organization

Your name:

Reply:


Posted by Jerry Stuckle on 09/26/07 05:03

Confused but working on it wrote:
> On 2007-09-25 03:49:42 -0700, Jerry Stuckle <jstucklex@attglobal.net> said:
>
>>> 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.
>
> Thanks Jerry,
>
> I changed the links to ful paths temporarily. Heavier sever load is
> better than bad links.
>
> I wrote an echo statement for the above line and found out my site isn't
> where I thought it was on my iMac. So I stuck it in my header file and
> did an upload to my real site and it gave me:
> /home/mysite/public_html Ths is correct and to my surprise worked when i
> wrote it into my include. This is a shared host and I'm sure a common
> setup so any security concerns here?
> <?php include($_SERVER['DOCUMENT_ROOT']."/header.php"); ?> Also worked
> which is what I think I'm really after.
>
> Before i do a mass find and replace anything else I should know?
>
> Thanks so much for the help.
>
> Ron
>

Nope, the beautiful thing is it works on any server where PHP is loaded
as a non-cgi.

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

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