Re: More include issues

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




I try not to bother the list and figure things out by myself as much as I
can, but it's hard when I was "volunteered" to become the guinea pig to
convert some of our apps from ColdFusion to PHP...especially when nobody I
work with has ever touched PHP before.  I have nobody to turn to except
google/forums/this list.


I feel ya brotha! I think Stut might be having a bad day...

Coldfusion, MSSQL, Informix, PHP, oh my!

So once again, thank you, and thanks to everyone else that is helping this
novice become more familiar with PHP.


Don't let the b*st*rds get you down, man.

A note about include paths: Unless you want to drive yourself totally batty,
always try to use absolute document paths when include/require'ing. I use a
simple constant that I stick at the top of every path I put together:

<code>
// The @ kills an error that would be produced
// if already defined
// Leave 'www/' empty if root path
// to current file is not a subdirectory
@define('INCLUDE_PATH_SUBDIRECTORY','www/');
@define('INCLUDE_PATH',
   $_SERVER['DOCUMENT_ROOT'] .
   (strrpos($_SERVER['DOCUMENT_ROOT'],'/') !==
   (strlen($_SERVER['DOCUMENT_ROOT'])-1) ? '/' : '') .
   INCLUDE_PATH_SUBDIRECTORY)
);
// Usage
// I recommend always using
// include_once and require_once
// unless you know for sure you
// need multiple includes for that
// file
include_once INCLUDE_PATH . 'Connections/conn.php';
</code>

This might output for INCLUDE_PATH:

"/inetpub/www/virtual/www_example_com/"

for example, which then becomes

"/inetpub/www/virtual/www_example_com/Connections/conn.php"

PHP will always know how to find that.

This works for me, but your usage or results may vary, and may not work on
all servers (IIS, for instance) or some Apache installations (I guess). Try
creating a test page and play around with it using echo and so on to see
what it outputs. You can contact me directly if the forum mungs it up on the
line-wrap.

Also try:

<code>
echo '<pre>';
print_r($_SERVER);
echo '</pre>';
</code>

To see what server variables are available. Just remember, webroot (public)
and docroot (private) are different things.

--
Jared Farrish
Intermediate Web Developer
Denton, Tx

Abraham Maslow: "If the only tool you have is a hammer, you tend to see
every problem as a nail." $$

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux