On Mon, Jul 6, 2009 at 11:04, Govinda<govinda.webdnat...@gmail.com> wrote:
> Kim, this is exactly what I was looking for.  I had been over $_SERVER in
> the docs..  but somehow missed that basic obvious param.  Thanks!

    And now I'll throw a monkey wrench into the gears and tell you
that, yes, it works, but don't always rely on it.  The path translated
to/from the web server may not be the real path.  And while you could
do your translation with realpath(), instead you should look into:

        <?php include(dirname(dirname(__FILE__)).'/include/file.php'); ?>

    The example above uses the always-on reserved constant __FILE__
for the file in which it's written, regardless of how it's accessed
(as an include, etc.).  So consider the following:


    In the example above, imagine that you access 'index.php', which
includes 'home.php', which - in turn - includes 'body.tpl.php' and
'file.php'.  Using $_SERVER data will use the information given to it
by the webserver at the point of the call: in this case, from
/home/user/public_html/index.php.  As such, the include path will be
relative to that.  So if you're including a file in ./web/home.php,
you will need to hard-code the adjustment to account for the

    Conversely, using the code example from above (and building upon
it), we know that __FILE__ remains static regardless of the point of
the call.  Thus, it's a better and more reliable method, and is usable
even if $_SERVER data is not available to the script.

    With this in mind, it should be quite simple to understand how the
following should work:

// My Name: /home/user/public_html/web/home.php

$file_to_include = dirname(dirname(__FILE__)).'/include/file.php';

if(file_exists($file_to_include) && is_readable($file_to_include)) {
} else {
    // Do your error handling here.

    .... but to each his/her own!  ;-P

</Daniel P. Brown>
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to