On 4/13/07, Alan in Toronto <Alantoronto@xxxxxxxxxxxxxxx> wrote: > Sorry, this is OT, but I'm a complete newbie to PHP and I know there are some smart > PHP coders in this group. If you would indulge me, could you please let me know the > best way to define paths for includes. > > Currently I'm working on a site that is located in a sub-directory of my web hosting > account. When it's complete, I'll move it to the server of the non-profit group I'm > doing this for, where presumably it will live at the web root (directly under the > domain name). Ideally I'd like to have to change some central variable rather than > have to change paths on every page or in every script. > > I found the attached posts in various PHP forums. I'm sure you are familiar with > many of those approaches. Please help my understanding and/or let me know what is > the best approach to use. > > Thanks very much for any assistance, and for understanding and allowing an > occasional OT post. Much of this depends on WHAT you are working on. It also depends where you are needing to use this kind of code. That is, if you have things like links and image tags in plain HTML, then just make sure all the files those point to are done with RELATIVE links. If you are writing code from scratch and need to point to files in the PHP side of things, I recommend doing what SM does - define your own "home" directory variable (constant is better) and use it EVERYWHERE you refer to a file in PHP. I would not use $_SERVER["DOCUMENT_ROOT"] unless you can guarantee it will be what you expect on your system and the target system. There is no real need to use this approach when you can simply write everything relative to the application's main directory. I also don't think you need to bother with trying to push your application's include path into the PHP settings, and in fact, I'd stay away from that too. It's just an excuse to have include() calls without path information, which is less readable code anyway. The "paths.inc" file is waaaay too high maintenance and easy to break; definitely wouldn't touch that one. I got tired of reading all these yahoos after that... here is how SM does it. Look at /src/compose.php: First thing it does is define the relative path to the main application directory. After that, all files are included using that constant. End of story. It does not matter where you install the codebase when done like this. The DEVEL branch does it slightly differently, where a central file is first included (you always know where it is relative to the current file) and it then does some magic to calculate the base directory constant. For your average website, just use the approach from STABLE, as it's painfully simple. If you need to calculate hrefs and things like that in the PHP code, it can be a little more complicated, but doesn't have to be for simple sites. See how SM calculates $base_uri in the sqm_baseuri() function in strings.php in STABLE (note that $PHP_SELF is constructed in the function php_self()). In most simple cases, you can simply include a "startup" file (after you define the constant pointing to your main app dir per above), and in that startup file, just set another constant that contains the base URI for use in hrefs and such things throughout the code. Then you only have to change that value when you move the site. -paul ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV -- squirrelmail-users mailing list Posting Guidelines: http://www.squirrelmail.org/wiki/MailingListPostingGuidelines List Address: squirrelmail-users@xxxxxxxxxxxxxxxxxxxxx List Archives: http://news.gmane.org/thread.php?group=gmane.mail.squirrelmail.user List Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=2995 List Info: https://lists.sourceforge.net/lists/listinfo/squirrelmail-users