Include path?

Status
Not open for further replies.

markspace

New Member
Messages
7
Reaction score
0
Points
0
I have a brand new free website. I was wondering: can I set a local include path, so that include files won't be served by the web server?

In other words, if I have a file like "db_pass.txt" that has all my passwords in it, and I don't want folks to be able to see this, is there some place that I can put it where there's no chance it'll ever be served up by the web server? Something not under the www directory at all.

Thanks for any help you can provide.
 

adamparkzer

On Extended Leave
Messages
3,745
Reaction score
81
Points
0
I have a brand new free website. I was wondering: can I set a local include path, so that include files won't be served by the web server?

In other words, if I have a file like "db_pass.txt" that has all my passwords in it, and I don't want folks to be able to see this, is there some place that I can put it where there's no chance it'll ever be served up by the web server? Something not under the www directory at all.

Thanks for any help you can provide.

Anything that is not in the public_html folder is not accessible by anybody else through their web browser. You can create a new folder inside your home directory that you can store your db_pass.txt file in, or you could just put the db_pass.txt file directly in your home directory (represented by a picture of a little house in the File Manager).
 

descalzo

Grim Squeaker
Community Support
Messages
9,372
Reaction score
326
Points
83
You do not have to mess with the include path.

You can supply an absolute path to require/include

PHP:
require_once( '/home/yourusername/etc/db_pass.txt') ;

Or you can supply a relative path...

PHP:
require_once( '../etc/db_pass.txt') ; [if your script is in /public_html]
 
require_once( '../../etc/db_pass.txt') ; [if your script is in a subdirectory of /public_html]

You do not have to adjust the include path.

But if you insist...

PHP:
$path = '/the/additional/path';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

will add your additional path for that one script.
 
Last edited:

markspace

New Member
Messages
7
Reaction score
0
Points
0
I have a simple test file:

<html><body>
<?php
echo "root_include.php:<br />\n";
include("/root_include.php");

echo "local_include.php:<br />\n";
include("local_include.php");

?>
</body></html>

The "local_include.php" file is found just fine, but "/root_include.php" isn't. It's possible I have a spelling error, but I've double checked it a couple of times now. What I'd really like to do is not have to use relative paths, which are clumsy and lock me in to specific directory structures.

Here's a typical error message:

[22-Sep-2009 21:19:30] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening '/root_include.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/redacted/public_html/test/include_test.php on line 4
Edit:
Thanks for this reply, descalzo, our posts crossed so if you're wondering why my post just above this one doesn't make much sense, I was not reply to you. ;)

You do not have to mess with the include path.

You can supply an absolute path to require/include

PHP:
require_once( '/home/yourusername/etc/db_pass.txt') ;

This one isn't very feasible because my home directory will change if the app gets moved elsewhere.

Or you can supply a relative path...

PHP:
require_once( '../etc/db_pass.txt') ; [if your script is in /public_html]
 
require_once( '../../etc/db_pass.txt') ; [if your script is in a subdirectory of /public_html]
You do not have to adjust the include path.
Again, if the internal directory structure of my PHP app gets changed (i.e., I want to change the locations of some files around), I'd have a large headache chasing down these relative strings and re-typing them.


But if you insist...

PHP:
$path = '/the/additional/path';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
will add your additional path for that one script.
This seems to be what I was looking for. At least, my paths should be in one spot, or at most one string per file to set the path string. Should be much nicer in the long run. Thanks!
Edit:
Well, crud, seems I hit the "edit" button. Sorry about the mess.
 
Last edited:
Status
Not open for further replies.
Top