I have been wondering: can you really shield a directory/file on the server in the outdoors world, but allow it to be available to PHP?

It's quite simple. I am caching web pages on my small server with PHP inside a certain directory, however i don't want web customers to see these files or ezinearticles directly. PHP, however, must have the ability to access these files (for everyone these to the consumer). That could seem not logical, but what I am attempting to do is restrict customers certain pages but still have the ability to cache these questions webserver-savvy format.

Ideally something with .htaccess or chmod.

Thanks!

Absolutely-- actually, you don't have to use .htaccess. To put it simply the protected directory above your document root (that's, store it near the folder where your PHP scripts are store, typically "htdocs," "httpdocs" or sometimes just "www').

So that your web files could be in /my/folders/httpdocs/, as well as your "protected" files could be in /my/folders/protected_folder/

The concept here's that PHP can access any folder around the server, but Apache will not allow the user navigate "above" the main directory.

To gain access to your directory, you should use:

$protected_path = $_SERVER['DOCUMENT_ROOT'].'/../protected_folder/';

(Incidentally, you pointed out you are carrying this out to cache pages-- you might like to take a look at Smarty, the PHP template engine, which pre-compiles your templates as well as supports really wise caching. And actually, among the Smarty "guidelinesInch would be to configure your structure therefore the template and cache files aren't in or underneath the document_root folder, so customers arriving from Apache can't ever reach them, however the Smarty PHP code can certainly grab whatever it requires after that.)

Sure, just put the files inside a directory outdoors of the web root. For example, in case your web root is /usr/local/apache/htdocs/ you may create a /usr/local/apache/private_cache/ directory that PHP should get access to, but there's no method of getting into it using a web request.

You may also put a .htaccess file composed from the line deny from all within the directory you need to safeguard. Which will prevent Apache (although not PHP) from serving in the files.