473,770 Members | 7,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make the include path universal?

Hi,

Im new to php and have a background in asp. All the help is very much appreciated.

today I was using the include function in a file that itself gets included :

***************
consumer.php : <? include "inc.php" ?>

inc.php : <? include "Common/functions.php" ?>

functions.php : common functions that all pages use
***************

This works fine if the path that's specified in
<? include "Common/functions.php" ?>
is relative to the path of the calling page consumer.php

I want to be able to specify <? include "inc.php" ?> in every page no matter
if its nested in a directory or not.

In asp I would use absolute paths like this : /Common/functions.php and it
would work.
PHP comes close to it when using paths like this : c:/website/site1/Common/functions.php

But thus breaks when I transfer the pages from the development server to
the live server cause there is no c:/website/site1

My next guess was that I could solve this with a variable like this : $docroot
.. "/Common/functions.php" but where do I specify $docroot in a central location?
(I would do this in asp's global.asa)

_SERVER["DOCUMENT_R OOT"] is blank when I request it and, if I understand
it correclty, I can set it in the php.ini . The problem is this value holds
for all the sites on the box.

I'm new to php so if I don't make sense than pls put me straight :)

Cheers,
Tom Pester

Sep 5 '05 #1
15 7408
In article <a1************ *************** @news.pandora.b e>,
tom pester <To************ ********@pandor a.be> wrote:
Hi,

Im new to php and have a background in asp. All the help is very much
appreciated.

today I was using the include function in a file that itself gets included :

***************
consumer.php : <? include "inc.php" ?>

inc.php : <? include "Common/functions.php" ?>

functions.php : common functions that all pages use
***************

This works fine if the path that's specified in
<? include "Common/functions.php" ?>
is relative to the path of the calling page consumer.php

I want to be able to specify <? include "inc.php" ?> in every page no matter
if its nested in a directory or not.

In asp I would use absolute paths like this : /Common/functions.php and it
would work.
PHP comes close to it when using paths like this :
c:/website/site1/Common/functions.php

But thus breaks when I transfer the pages from the development server to
the live server cause there is no c:/website/site1

My next guess was that I could solve this with a variable like this :
$docroot
. "/Common/functions.php" but where do I specify $docroot in a central
location?
(I would do this in asp's global.asa)

_SERVER["DOCUMENT_R OOT"] is blank when I request it and, if I understand
it correclty, I can set it in the php.ini . The problem is this value holds
for all the sites on the box.

I'm new to php so if I don't make sense than pls put me straight :)


You can specify the include_path in php.ini to a path shared by all
environments.

include_path on your dev machine could be c:/websites/includes/ and on your
server c:/includes/ and keep them in sync.

--
Sandman[.net]
Sep 5 '05 #2
Hi Sandman,

Reading further upon the subject I found your solution.

I have some problems with it though :

- There is only 1 php.ini for all the sites on the server so I will end up
putting all includes of different projects in 1 directory (I could prepend
the include file with a project prefix to avoid naming collisions)
- Or I could expand include_path and add a directory per site (naming collisions
are possible again so I have to adopt a naming scheme)
- I read that some isp's don't allow editing the php.ini (especialy if you
are using a shared server, there is only 1 php.ini right?)
- The site isn't self contained. I can't xcopy 1 directory to deploy are
backup the site. Information is scatered around the system.

disclaimer :
This are all comments of a php beginner so _please_ correct me if I'm wrong.

Cheers,
Tom Pester

You can specify the include_path in php.ini to a path shared by all
environments.

include_path on your dev machine could be c:/websites/includes/ and on
your server c:/includes/ and keep them in sync.

Sep 5 '05 #3
We solve the prolbem by defining a base "vars.php" file at the "root"
of the site.

In there we define paths to constants, and then these constants are
used to INCLUDE files as needed.
var.php

define( INCLUDE_PATH, '/my/path/includes/');

now I can incluse my files as Ineed

include_once INCLUDE_PATH . 'base_functions .php';
All you need to do is update that one constant as you move from site to
site and it works fine.

Linux or windows.

walter

Sep 6 '05 #4
phpWalter wrote:
We solve the prolbem by defining a base "vars.php" file at the "root"
of the site.

In there we define paths to constants, and then these constants are
used to INCLUDE files as needed.
var.php

define( INCLUDE_PATH, '/my/path/includes/');

now I can incluse my files as Ineed

include_once INCLUDE_PATH . 'base_functions .php';
All you need to do is update that one constant as you move from site to
site and it works fine.

Linux or windows.

walter


Walter,

Looks like unnecessary work to me. And what happens if the root
directory of the site is moved? Or you need to use the same pages on
another server? Everything breaks until you change your var.php.

I'd rather use something like:

include_once($_ SERVER['DOCUMENT_ROOT'].'/includes/base_functions. php');

This changes automatically based on your Apache document root setting.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Sep 6 '05 #5
Hi Walter

This is a good solution that AFAIK minimizes the poblem cause you still have
to include var.php in each file.
And the path to the var.php suffers the same problems now but it's only here
that the problem surfaces.

**** code ****
include_once 'var.php'; // You didn't mention this line but its required
in every file right?
include_once INCLUDE_PATH . 'base_functions .php';
**** code end ****

the
include_once 'var.php'
is not universal for each file since it breaks if the file that includes
it is in another directory, fe ;

include_once 'var.php'
becomes
include_once '../var.php'

For the rest its a fine solution. Can you conform that's how you ment it?
I'm still learning the details of the language..

Cheers,
Tom Pester
We solve the prolbem by defining a base "vars.php" file at the "root"
of the site.

In there we define paths to constants, and then these constants are
used to INCLUDE files as needed.

var.php

define( INCLUDE_PATH, '/my/path/includes/');

now I can incluse my files as Ineed

include_once INCLUDE_PATH . 'base_functions .php';

All you need to do is update that one constant as you move from site
to site and it works fine.

Linux or windows.

walter

Sep 6 '05 #6
Hi Jerry,

Using $_SERVER['DOCUMENT_ROOT'] is indd the standard php way but my problem
is that it's not defined on a windows IIS box (I confirmed this by reading
previous posts).

Cheers,
Tom Pester
phpWalter wrote:
We solve the prolbem by defining a base "vars.php" file at the "root"
of the site.

In there we define paths to constants, and then these constants are
used to INCLUDE files as needed.

var.php

define( INCLUDE_PATH, '/my/path/includes/');

now I can incluse my files as Ineed

include_once INCLUDE_PATH . 'base_functions .php';

All you need to do is update that one constant as you move from site
to site and it works fine.

Linux or windows.

walter

Walter,

Looks like unnecessary work to me. And what happens if the root
directory of the site is moved? Or you need to use the same pages on
another server? Everything breaks until you change your var.php.

I'd rather use something like:

include_once($_ SERVER['DOCUMENT_ROOT'].'/includes/base_functions. php')
;

This changes automatically based on your Apache document root setting.

Sep 6 '05 #7
Hi Jerry,

Using $_SERVER['DOCUMENT_ROOT'] is indd the standard php way but my
problem is that it's not defined on a windows IIS box (I confirmed this
by reading previous posts).

Cheers,
Tom Pester


Tom,

(please don't top post).

Hmmm, it exists in my IIS setup (W2K, PHP 5.0.3).

Of course, there's always $_SERVER["APPL_PHYSICAL_ PATH"] which also
seems to contain the path to the document root. But I haven't used it.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Sep 6 '05 #8
> (please don't top post).

"This term is generally used pejoratively with the implication that the offending
person is a newbie, a Microsoft addict (Microsoft mail tools produce a similar
format by default), or simply a common-and-garden-variety idiot."

Will do Jerry :)
Hmmm, it exists in my IIS setup (W2K, PHP 5.0.3).


I get this message when using it :
Notice: Undefined index: DOCUMENT_ROOT in C:\Inetpub\wwwr oot\PHP\Pages\t est.php
on line 2

I've tested it on :

WXP,IIS5.1,PHP 5.0.3
and
W2003server,IIS 6.0,PHP 5.0.3

Cheers,
Tom Pester
Sep 6 '05 #9
tom pester wrote:
(please don't top post).

"This term is generally used pejoratively with the implication that the
offending person is a newbie, a Microsoft addict (Microsoft mail tools
produce a similar format by default), or simply a
common-and-garden-variety idiot."

Will do Jerry :)


Sorry, I really didn't mean to imply anything. Some groups top post,
others (like this one) bottom post.
Hmmm, it exists in my IIS setup (W2K, PHP 5.0.3).

I get this message when using it :
Notice: Undefined index: DOCUMENT_ROOT in
C:\Inetpub\wwwr oot\PHP\Pages\t est.php on line 2

I've tested it on :

WXP,IIS5.1,PHP 5.0.3
and
W2003server,IIS 6.0,PHP 5.0.3
Cheers,
Tom Pester


Interesting. What does phpinfo() show? And did you try
$_SERVER["APPL_PHYSICAL_ PATH"]? I'm wondering if this one works.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Sep 7 '05 #10

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

Similar topics

3
6691
by: Charts | last post by:
I recently upgraded development web server to Windows 2003. I have ASP file contains following line for include file <!--#include File="../Include/adovbs.inc"-- This ASP file worked fine before. When I ran this file under Windows 2003, I got following error message The include file “Include/adovbs.inc” cannot contain ‘…’ to indicate the parent directory. I changed to following lin <!--#include File="my virtual...
1
5462
by: Intaek LIM | last post by:
hi guys. i just got a library for generating packets. but, i can't compile the example source because of bad include path. ------------------------------------------------------------------------ D:\libnet\sample>gcc tcp1.c In file included from tcp1.c:36: libnet_test.h:12:31: ../include/libnet.h: No such file or directory In file included from tcp1.c:36: libnet_test.h:24: parse error before "enet_src"
13
2580
by: alex | last post by:
Hi, I've got a php script located at : http://localhost/browse/script.php This script is "URL-rewrited" as http://localhost/welcome.htm This script includes other scripts with the following code : <?php include("../inc/connect.php") ; ....
2
3488
by: thuang2 | last post by:
Hi, How can I add more include path to gcc compiler on RHEL3? When re-compile C source code, do I have to do a "touch" command (by typing "touch myfile.c") before running "make" command? Thanks.
1
10846
by: floatingpoint | last post by:
Hi, I have gathered all my constants in one .h file and I want to use them in my classes, which are all in a directory called Classes. The problem is about the scope. The Constants.h is at the same level as Classess directory, so that my classes do not see Constants.h: The case is like this: My_project\Classes\class_a.h My_project \Classes\class_a.cpp My_project\Constants.h
11
26638
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package and PEAR is in c:\wamp\php\pear I modified php.ini in the c:\wamp\php directory to reflect the actual path, but even stopping and restarting my server shows the c: \php5\pear path. I can't change it no matter what I do I also tried the...
2
3792
by: dave6502 | last post by:
Struggling newbe here, some of my #includes work, some dont. Is it possible to list the include path ? (in BASH), I have looked at the environmental variables (loads of them) but cannot find a reference. Cheers Dave
12
2548
by: Gutspiller | last post by:
I am new here (Hello!), I am trying to fix a problem that some of the pages of my site are displaying the following error: Warning: getimagesize(./swf/FWG Bridge_july_4th_2008.swf ) : failed to open stream: No such file or directory in /home/games4w/public_html/games/system.class.php on line 430 The thing is some pages aren't. On the pages that display the error, it's not loading up my content either (flash games). I talked to my...
0
9592
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9425
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
10058
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...
0
9870
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...
1
7416
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
6678
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();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.