PHP Includes

PHP Includes

Posted by: MarkWoodward
Posted on: 2006-06-24 18:25:00

Hi all,
Is there a default folder I should be using for include files (php)?
At the moment I'm sticking them 1 level above the document root and calling them with 'require_once(../folder/file.php). This will get messy when I start doing something like ../../../folder/file.php as I drill down within the site.

Is there a way to have 'folder' in the include path?
Do we have a personal php.ini file?
How do you all handle this?

phpinfo() shows a path of .:/usr/local/php5/lib/php. Obvious not the place to put them even if I had access.

As you can tell I'm a newbie at this. Any php I've done has been done locally. First time using an actual host.

thanks,

Re: PHP Includes

Posted by: scjessey
Posted on: 2006-06-24 19:01:00

When doing PHP includes, your best bet is to put all the files you want to include in the same folder. For example, http://example.com/includes/. Then you can perform the include by using the DOCUMENT_ROOT environment variable:

<?php include($_SERVER['DOCUMENT_ROOT']."/includes/file.php"; ?>

That is functionally equivalent to:

<?php include("/home/username/domain.com/includes/file.php"; ?>

--------
Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code SCJESSEY97

Re: PHP Includes

Posted by: MarkWoodward
Posted on: 2006-06-24 22:41:00

Thanks Simon,

the only issue with this is if someone types www.example.com/includes they get a listing of all the include files!! Which is no good if there's sensitive info in there. I realise I can call the folder 'fdg@321' for eg instead of 'includes' and that I can stick an index.php that redirects the user away from the includes folder, but apparently (or so I've heard/read) it's 'safer' to have the includes folder outside the document root and was just wondering if that's possible on DreamHost? Am I being paranoid?

thanks,

Re: PHP Includes

Posted by: scjessey
Posted on: 2006-06-25 05:28:00

In reply to:

the only issue with this is if someone types www.example.com/includes they get a listing of all the include files! ... Am I being paranoid?


You can prevent directory listing by creating an .htaccess file containing the following line:

Options -Indexes

Put that in the directory you are trying to protect. If you put it in your root directory, it will protect ALL directories.

Re: PHP Includes

Posted by: Ashley
Posted on: 2006-06-29 04:06:00

You can set the include path at runtime. Have a look at

http://uk.php.net/manual/en/function.set-include-path.php

Re: PHP Includes

Posted by: scjessey
Posted on: 2006-06-29 07:46:00

In reply to:

You can set the include path at runtime. Have a look at

http://uk.php.net/manual/en/function.set-include-path.php


As far as I know, that doesn't work when PHP is running as a CGI application.

Re: PHP Includes

Posted by: guice
Posted on: 2006-06-29 08:37:00

In reply to:

As far as I know, that doesn't work when PHP is running as a CGI application.


That option works with PHP CGI. It's the php_value option that does not.

Re: PHP Includes

Posted by: kchrist
Posted on: 2006-06-29 09:54:00

And if all else fails, you can always use ini_set() under either mod_php or PHP-CGI.

Tags: php includesfile phpphpinfoini filepathphp5messyusrnewbieliblocalaccesspersonal