Re: Best practice question regarding set_include_path()

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

 



On Thu, May 10, 2012 at 1:50 PM, admin <admin@xxxxxxxxxxxxxxxxxxx> wrote:
>
>
> -----Original Message-----
> From: Al [mailto:news@xxxxxxxxxxxxx]
> Sent: Thursday, May 10, 2012 11:44 AM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Best practice question regarding set_include_path()
>
> For my applications, I've been using includes and other file addressing by
> using the doc root as the base dir.   e.g.
> require_once $_SERVER['DOCUMENT_ROOT'] .
> '/miniRegDB/includes/miniRegDBconfig.php';
>
> Recently, I ran into a problem with a new installation on a shared host
> where the doc root was assigned in an unusual manner. I rather not require
> setting a custom base dir [instead of $_SERVER['DOCUMENT_ROOT']'] for my
> applications.
>
> So, I was wondering if it would be good practice to use the
> set_include_path() and add the base dir for my applications.  I've used this
> for dealing with Pear function files on shared servers and had no problems.
>
> Need some guidance regarding this subject.
>
> Thanks....
>
> --
>
> I use define to set the application path
> define('BASE_PATH','C:\\inetpub\\vhosts\\yourwebsite.com\\httpdocs\\');
>
> Example:
> require_once (BASE_PATH. '/miniRegDB/includes/miniRegDBconfig.php');
>
>
> works great for JQuery paths
>
> <script>
> $(document).ready(function() {
> $('#dareport').html('<img src="<?php echo BASE_URL;?>images/loading.gif"
> />');
> });
> </script>
>
> To me it is much better than set_include_path() but works in the same
> premise
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

I tend to use a slightly more portable version:

define('APP_ROOT',dirname(__FILE__));

in a configuration file. (If the configuration file happens to be at a
different depth than the main application file(s), I stack on more
dirname's to get back to the application root.)

Similarly, I usually need an application URL path. This can be
trickier, depending on how you structure your application. This
generally works for the applications I develop:

define('APP_URL_BASE','http://'.$_SERVER['HOST_NAME'].dirname($_SERVER['SCRIPT_NAME']));

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




[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