473,804 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

includes and paths and organization

Ron
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("includ es/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


Sep 25 '07 #1
4 1835
In our last episode, <20070925000728 16807-PostInGroups@wh erevercom>, the
lovely and talented Ron broadcast on comp.lang.php:
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.
There is. Write a php function to calculate relative paths.

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 483 days to go.
What do you do when you're debranded?
Sep 25 '07 #2
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("includ es/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_pat h().PATH_SEPARA TOR.'/home/bla/public_html/includes';

ini_set("includ e_path",$newInc ludePath);
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
Sep 25 '07 #3
Erwin Moller <Si************ *************** *************** @spamyourself.c omwrites:

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_pat h().PATH_SEPARA TOR.'/home/bla/public_html/includes';

ini_set("includ e_path",$newInc ludePath);
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).
I would vote for Erwin's solution since it will give you
much more flexibility in include location. Readup on "include_pa th"
in on the php web site; also, some people may now know that you can use
relative paths in the include_path directive, so this is okay:

include_path = ".:lib:../lib:../../lib"

NOTE, the "." is added first since the normal PHP use of the include_path
is to search the include_path FIRST, if the file is not found along those
paths, look in the default dir (which is usually what you might not expect).

Hope this helps.

--
John
_______________ _______________ _______________ _______________ _______
John Murtari Software Workshop Inc.
jmurtari@follow ing domain 315.635-1968(x-211) "TheBook.Co m" (TM)
http://thebook.com/
Sep 26 '07 #4
Ron
On 2007-09-25 22:03:51 -0700, Jerry Stuckle <js*******@attg lobal.netsaid:
>>

Nope, the beautiful thing is it works on any server where PHP is loaded
as a non-cgi.
I started a file for all my little snippets. The hard thing is not
knowing where to look in the manual sometimes.

I use my iMac as a test sever as it comes loaded with php4. The path
reurned isn't really where you think it is so the include fails. Minor
issue as it works great in the real world.

Thanks again,
Ron

Sep 26 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2742
by: Tim Tyler | last post by:
A fairly simple question: I have a library A which depends on library B and C. Currently I have: <?php include("A.inc.php"); include("B.inc.php"); include("C.inc.php");
4
1277
by: Ben | last post by:
This is probably a very simple question (I hope), but my usually great web searching abilities have not turned up the answer I am looking for. I have a php page that includes a file for example index.php has an include for menu.htm. Inside menu.htm are some images in the same directory. All works great in that scenario. Here's where the trouble begins. If I want to include menu.htm inside a php file that is in another directory (say...
2
3496
by: Mike | last post by:
Hello, I'm working on a new site that has a nearly empty index file (variable location) that includes a template file (set location) which in turn includes two data files (variable location dependent on index file's location). This concept worked in PHP and I'm just playing around with it in ASP to see if it can make my site management easier because I can't move to Apache for a while. It seems that the template file can only include...
7
2093
by: jason | last post by:
I am getting twisted by the possibility that my virtual includes which currently work great on non-domain remote IP will crash if I purchase a domain and point it to one of my designated folders.....Here is the scenario and question:: If my remote webhost at (eg): http://69.8.9.9 ....has a subfolder with with:
6
2990
by: ceyhun | last post by:
When I use an include file like this <!--#include file="..\..\cfig.asp"--> <!--#include file="..\..\clsOOPModule.asp"--> my server gives an error of : Active Server Pages error 'ASP 0131' Disallowed Parent Path /test/module/VieBoard/main.asp, line 1
3
8230
by: SuryaPrakash Patel via SQLMonster.com | last post by:
Hello, There are three tables: OS-GroupOFCompanies (Table1) GoC_GroupOFCompaniesID (PK) OS-Organization (Table 2) Org_OrganizationID (PK)
1
1213
by: paddy | last post by:
I keep digging through tut after tut and I find lots and lots of C++ logic, but I can't find any straight forward plain and simple info on the whole linking and library process. Can anyone recommend a good source to digest that covers what is going on in this regard? I can get things to work with the 'monkey see' technique but it is still all voodoo. I need to understand things like, how make files work, how vc++6 project files work,...
3
2539
by: Jeff | last post by:
I have an asp page. Now I know this is sortof OT, but I am not sure of the forum to get an answer. I have an include on this asp page <!-- #include file=\forum\includes\consts-inc.asp --> now, it gives me this error: File attribute '\forum\includes\consts-inc.asp' cannot start with forward slash or back slash.
6
7983
by: MaiyaHolliday | last post by:
Hello, I've recently installed apache on a new computer, and cannot figure out why my site will not process any includes. (it was working on my old one) There are no errors on the page such as "include not found", rather much of the page is blank where the included menus, etc would be, and the CSS is not attached. thanks so much!!! My httpd.conf looks like this:
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.