943,917 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3085
  • PHP RSS
Nov 30th, 2005
0

specifying home dir

Expand Post »
I am trying to create a script and I want to be able to say [php]require "~/functions/functions1.php";
require "~/functions/functions2.php";
require "~/functions/functions3.php";[/php]

but php doesn't seem to understand what the tilde means (and yes this for a linux server). Is there any way I can specify the home dir without actually having to point it to to absolute path? A relative path wouldn't work because I won't know how many folders some of these files will be in
Similar Threads
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Nov 30th, 2005
0

Re: specifying home dir

One method would be to define a global var to hold the absolute path to the specified folder. You can then use the global var in the require function to build the path to the file required. Example:
[PHP]define('FUNCTION_PATH', 'http://127.0.0.1/devsite/functions/');
// the FUNCTION_PATH var can then be used like:
require(FUNCTION_PATH.'functions1.php');
require(FUNCTION_PATH.'functions2.php');
require(FUNCTION_PATH.'functions3.php');[/PHP]
Reputation Points: 16
Solved Threads: 7
Junior Poster
Lafinboy is offline Offline
166 posts
since Jul 2004
Nov 30th, 2005
0

Re: specifying home dir

There are more than likely server configurations that are preventing you from accessing the file in ~/functions/. This is primarily due to security issues.

Also, you probably should specify which user's home directory you want to go from (i.e. ~johndoe/functions/).

-Fredric
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
Daishi is offline Offline
80 posts
since Aug 2005
Nov 30th, 2005
0

Re: specifying home dir

Quote originally posted by Daishi ...
There are more than likely server configurations that are preventing you from accessing the file in ~/functions/. This is primarily due to security issues.

Also, you probably should specify which user's home directory you want to go from (i.e. ~johndoe/functions/).

-Fredric
The reason I did it that way was because I can easily go type the following in SSH and it works just fine
PHP Syntax (Toggle Plain Text)
  1. ls ~
so it's not which user, the tilde... (at least as I understand it) searches your OWN home dir so there is no need to specify which user at least on the servers I am working on
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Nov 30th, 2005
0

Re: specifying home dir

Quote originally posted by paradox814 ...
I am trying to create a script and I want to be able to say [php]require "~/functions/functions1.php";
require "~/functions/functions2.php";
require "~/functions/functions3.php";[/php]

but php doesn't seem to understand what the tilde means (and yes this for a linux server). Is there any way I can specify the home dir without actually having to point it to to absolute path? A relative path wouldn't work because I won't know how many folders some of these files will be in
I was really trying to having to avoid doing the absoluate path, even though I know I could call on $_SERVER to generate the path for me in the example you gave. So is there no way to specify your own home dir in PHP?
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: i need help, total newb here :)
Next Thread in PHP Forum Timeline: How to calculate previous date?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC