safe_mode_include_dir
Hi Tony,
dirname(__FILE__) will always give you the script's directory, while
dirname(dirname(__FILE__)) would be equivalent to dirname(__FILE__).'/..'
which is what you are doing now.
Using relative paths is not a good idea, but if you have other people's code
to deal with, you'd better off creating an .htaccess file or editing the
virtualhost configuration than checking file by file for relative paths and
converting them to absolute paths (even with linux tools like sed or awk...
there's no warranty you'll do it right).
AFAIK, when you use relative paths, there are three things to take into
account:
1 - The script that's handling the request (the one that gets called first
and loads every other script). I think this can be queried through
$_SERVER['PHP_SELF'].
2 - The value for the PHP include path which you can obtain using
get_include_path().
3 - The current directory which you can obtain using getcwd(). Usually this
is the directory of the script that got called at first (but this is not
always the case).
However...this is a quote from my offline version of the extended PHP
manual...
"Files for including are first looked for in each include_path entry
relative to the current working directory, and then in the directory of
current script. E.g. if your include_path is libraries, current working
directory is /www/, you included include/a.php and there is include "b.php"
in that file, b.php is first looked in /www/libraries/ and then in
/www/include/. If filename begins with ./ or ../, it is looked only in the
current working directory."
So... provided that you are using "./script.php" and/or "../script.php"
what's the value for the current directory before you throw the
"require_once"? can you do an "echo getcwd()" in the line above the
"require_once" for testing purposes? Is that what you expect?
Also, keep in mind that for the safe_mode_include_dir directive to work
properly for relative paths, you must also add the shared path to the
include_path directive. Another quote of my offline PHP manual...
"safe_mode_include_dir string
UID/GID checks are bypassed when including files from this directory and its
subdirectories (directory must also be in include_path or full path must
including).
As of PHP 4.2.0, this directive can take a colon (semi-colon on Windows)
separated path in a fashion similar to the include_path directive, rather
than just a single directory.
The restriction specified is actually a prefix, not a directory name. This
means that "safe_mode_include_dir = /dir/incl" also allows access to
"/dir/include" and "/dir/incls" if they exist. When you want to restrict
access to only the specified directory, end with a slash. For example:
"safe_mode_include_dir = /dir/incl/"
If the value of this directive is empty, no files with different UID/GID can
be included in PHP 4.2.3 and as of PHP 4.3.3. In earlier versions, all files
could be included."
Anyway... for the sake of simplicity you can live with adding
dirname(__FILE__) everywhere for now.... but you'll see how bad it will be
if you have to modify one thousand scripts in this way, with variations such
as require/include, once/not-once, parenthesized/not-parenthesized. And you
will risk breaking legitimate scripts.
So... for the future, think about it.
Rob
Andrés Robinet | Lead Developer | BESTPLACE CORPORATION
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308
| TEL 954-607-4207 | FAX 954-337-2695
Email: info@bestplace.net | MSN Chat: best@bestplace.net | SKYPE:
bestplace | Web: http://www.bestplace.biz | Web: http://www.seo-diy.com
|