I am trying to create a script and I want to be able to say

require "~/functions/functions1.php";
require "~/functions/functions2.php";
require "~/functions/functions3.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

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:

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');

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

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

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

I am trying to create a script and I want to be able to say

require "~/functions/functions1.php";
require "~/functions/functions2.php";
require "~/functions/functions3.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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.