As per the Codex,
http://codex.wordpress.org/Integrating_WordPress_with_Your_Website
<?php
require('/the/path/to/your/wp-blog-header.php');
?>
Whether or not your means and method is foolproof is entirely dependent upon your setup and the locations in which you are placing your scripts, relative to your WordPress installation.
Assuming you follow the convention outlined in your code, then you should be OK.
You should provide a more detailed example of script locations (including any possible variations), versus WordPress location, so if someone has something to add that can refine your code, it'd then make sense, as your snippet is to localized to your use case.
UPDATE#
(in response to your comment)
The path to your WordPress installation is a constant, so instead of devising some trickery to figure out where that path lay, state it as is and in full, just like the example above.
If for example your actual path (for localhost) is something like;
c:\apache\htdcos\wordpress
...then,
//document root being c:\apache\htdocs
$_SERVER["DOCUMENT_ROOT"] . '/wordpress/wp-blog-header.php';
Will locate your document root, for which you then specify the your install directory and wp-blog-header.php
file.
I would then place a .htaccess
file in c:\apache\htdocs
which amongst other things should include the following,
php_value auto_prepend_file "auto_inc.php" //the auto_inc.php can be a name of choice
This will include (auto_prepend) the file auto_inc.php
before any other PHP file so if you have a directory structure like,
..\htdocs\ (root)
..\htdocs\project1\
..\htdocs\project2\
..\htdocs\project-test\sample\
..\htdocs\wordpress\
..\htdocs\.htaccess
..\htdocs\auto_inc.php
..\htdocs\index.php
The auto_inc.php
file will be included in any of the sub-directories, no matter depth.
Now within this automatically included file, you can place a function that wraps the require('/the/path/to/your/wp-blog-header.php');
for which you can arbitrarily use within your various projects, for example;
function wp_function_include() {
$path = require('/the/path/to/your/wp-blog-header.php');
echo $path;
}
wp_functions_include(); //which fires the verbose require(path..wp-blog-header.php)
Or alternatively, you need not wrap the require
at all and have it be available to you on every file, sub-directory, at any depth, without ever having to specify it again, allowing you to focus on your projects.
Seeing as the /wordpress/
directory already has a .htaccess
of its own, it won't be affected by the .htaccess
found within its root directory, removing any clash between declaring functions twice.