note 86881 deleted from function.getcwd by danbrown
| From: | danbrown@php.net | Date: | Fri, 07 Nov 2008 18:01:55 +0000 |
| Subject: | note 86881 deleted from function.getcwd by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146295@lists.php.net to get a copy of this message | ||
Note Submitter: BigueNique at yahoo dot ca
----
Hey folks, here are a few tips.
First, realpath() doesn't work in safe mode, so don't rely on it if you plan to deploy
your site on a webfarm.
Second, the quickest most reliable way to get the directory in which a script resides is to use
"dirname(__FILE__)", so if you want to include, let's say /var/www/mysite/A.php from
/var/www/mysite/B.php, no matter from which directory B.php was invoked:
<?php
include dirname(__FILE__) . "/B.php";
?>
Be careful when using $_SERVER values, as they might not be available on all platforms. I strongly
suggest dumping the $_SERVER superglobal on different PHP setups you wish to support (Apache on
Linux/Windows, IIS, etc...) before deciding to use them.
Also keep in mind that $_SERVER keys starting with 'HTTP_' have been sent by the client
(these are the request's HTTP headers), so their values are 1. not 100% reliable and 2. could
be tweaked by an evilish user trying to break your site security.