473,465 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

determine home directory?

I'm working on a PHP site and I have my database password file behind
the server root directory.

I can reference the password file by include("../
database_password.inc.php"), but I would like to make the code more
portable and not have this relative path reference. Is there a way I
can know for certain what the home directory is called?

As i'm developing this project in version control, I sometimes
checkout a development branch. I want to interact with this branch, so
I put it in its own directory under the web root directory. E. g.
/home/user/website-root
hosts the site, and
/home/user/website-root/development-branch
is where I'm testing my development.

Of course, this breaks the relative path reference in the development
branch.

I could set up another parallel site, e.g.
/home/user/development-webhost-root/
and that would properly reference the password file, but I'd rather
just have my checkout under the web root. That way my code is more
portable, and I could deploy it

I could make a configuration file where I specify the reference, but
that adds an extra step when I do a checkout or export from source
control -- I need to copy in my local configuration file. It would be
great if I could have a "zero-configuration" app ( provided that the
password file already exists in the home directory).

I could try to figure out the home directory from the script path, but
that is based on the assumptions of the directory layout that this
particular hosting provider is using. If we deploy on another host, I
would have to have this "just work".

If could do something like include($_HOME . "/password.inc.php"); that
would make things so much simpler. Is this possible?


Oct 22 '08 #1
6 14501
lawpoop wrote:
I can reference the password file by
include("../database_password.inc.php"), but I would like to make the code
more portable and not have this relative path reference.
Pardon me - you want to make the code more portable by NOT using relative
paths?
Is there a way I can know for certain what the home directory is called?
Yeah, it's always called "~".

--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

You will always get the greatest recognition for the job you least like.

Oct 22 '08 #2
On Wed, 22 Oct 2008 23:05:00 +0200, lawpoop <la*****@gmail.comwrote:
I'm working on a PHP site and I have my database password file behind
the server root directory.

I can reference the password file by include("../
database_password.inc.php"), but I would like to make the code more
portable and not have this relative path reference. Is there a way I
can know for certain what the home directory is called?
Dubious usage of 'home' directory. Home of a user, of document root? If
the latter:

echo realpath($_SERVER['DOCUMENT_ROOT'].'/../');
--
Rik
Oct 22 '08 #3
lawpoop wrote:
I'm working on a PHP site and I have my database password file behind
the server root directory.

I can reference the password file by include("../
database_password.inc.php"), but I would like to make the code more
portable and not have this relative path reference. Is there a way I
can know for certain what the home directory is called?

As i'm developing this project in version control, I sometimes
checkout a development branch. I want to interact with this branch, so
I put it in its own directory under the web root directory. E. g.
/home/user/website-root
hosts the site, and
/home/user/website-root/development-branch
is where I'm testing my development.

Of course, this breaks the relative path reference in the development
branch.

I could set up another parallel site, e.g.
/home/user/development-webhost-root/
and that would properly reference the password file, but I'd rather
just have my checkout under the web root. That way my code is more
portable, and I could deploy it

I could make a configuration file where I specify the reference, but
that adds an extra step when I do a checkout or export from source
control -- I need to copy in my local configuration file. It would be
great if I could have a "zero-configuration" app ( provided that the
password file already exists in the home directory).

I could try to figure out the home directory from the script path, but
that is based on the assumptions of the directory layout that this
particular hosting provider is using. If we deploy on another host, I
would have to have this "just work".

If could do something like include($_HOME . "/password.inc.php"); that
would make things so much simpler. Is this possible?


$_SERVER['DOCUMENT_ROOT'] always contains the root directory of the web
server. So you can access your file by
$_SERVER['DOCUMENT_ROOT'] . '/../password.inc.php'.

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

Oct 23 '08 #4
On Oct 22, 7:18*pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
Dubious usage of 'home' directory. Home of a user, of document root? If *
the latter:

echo realpath($_SERVER['DOCUMENT_ROOT'].'/../');

Thanks for replying, Rik. What would you say is the best practice in
this case? Using a config file?
Oct 23 '08 #5
On Oct 22, 5:27*pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>
Pardon me - you want to make the code more portable by NOT using relative
paths?
In this case, yes. If you want to have a password stored in a file,
but don't want the webserver to serve it, where would you put it, and
how would you reference it? The added wrinkle is that you want to be
able to install the php files in any directory under the web root, so
you can't just say "../" -- you could be three directories under the
web root, in which case the password file would be going in a
publically served directory, presumably with other things in that
directory already.
>
Is there a way I can know for certain what the home directory is called?

Yeah, it's always called "~".
That works in the shells, but PHP doesn't apparently seem to know it:

Warning: dir(~) [function.dir]: failed to open dir: No such file or
directory

Warning: dir(~/) [function.dir]: failed to open dir: No such file or
directory

Oct 23 '08 #6
On Oct 23, 12:09*am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>
$_SERVER['DOCUMENT_ROOT'] always contains the root directory of the web
server. *So you can access your file by
$_SERVER['DOCUMENT_ROOT'] . '/../password.inc.php'.
Thanks, Jerry. That's what I'm looking for!
Oct 23 '08 #7

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

Similar topics

5
by: Mike | last post by:
Does python support named semaphores for Linux? I saw that ActivePython for Win32 does. Can I get a list of currently running processes? I already posted in the GTK forum about looking for the...
5
by: bart plessers | last post by:
Hello, Currently I am developping a internet "directory browser" My page 'default.asp' has following entries: CurrentPATH = Request("MyLink") Set oFSO =...
4
by: Ed | last post by:
Hello All, I posted earlier about a problem I was having with editing or pasting/deleting files in the "Home Directory" of my web server. I just noticed that the "Home Directory" option in the...
13
by: could ildg | last post by:
I want to check if a folder named "foldername" is empty. I use os.listdir(foldername)== to do this, but it will be very slow if the folder has a lot of sub-files. Is there any efficient ways to do...
6
by: Hemant Shah | last post by:
Folks, I need to move HOME directory of an instance to another directory. What is the best way of doing it? Is changing password file enough? or dies DB2 store this info in it's own config? ...
22
by: Sunner Sun | last post by:
Hi, all Since the OS look both ASCII and binary file as a sequence of bytes, is there any way to determine the file type except to judge the extension? Thank you!
4
by: jmg3000 | last post by:
What's the customary way to keep your own local Python and package directory? For example, when you're on a server where you don't have root access, and everything must go in your home directory. ...
17
by: robbieg | last post by:
Hey all, first post here and as im sure once i ask my question.. you will all know that i am very new the shell scripting. I spend all of time in php, not shell. I need to figure out a way to...
9
by: Scott | last post by:
What is the most reliable method to determine the folder a script is running in? I was looking at the globals in $_SERVER but all the variables also listed the actual file the script was running...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
1
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.