Hi Ben,
I have looked at this snippet a bunch of times, and I am trying to understand how it would be used.
So lets say our PHP_SELF is
Code:
/this/is/my/script.php
Folcnt contains the nesting depth: 4
Then we build a string that contains "../" x folcnt. Incidentally, you could do this with
Code:
str_repeat("../",$folcnt-1)
And the "else" part of the isn't necessary as you already set $folappstep to "" before deciding whether you need to run the for loop.
Anyway, it has dawned on me why you'd want to do this. You want to pull the required files from the root of your webspace, whereas "require" works from the root of the file system.
Here is your code with the simplifications I mentioned:
Code:
$folcnt = substr_count($_SERVER["PHP_SELF"], "/");
$folappstep = str_repeat("../",$folcnt-1);
$extfile = $folappstep."ws8_extensions.php";
$funfile = $folappstep."ws8_functions.php";
include $extfile;
include $funfile;
However, what you want is for your scripts to be aware of the document root, and pull their included files from there. Consider this:
Code:
ini_set("include_path", getenv("DOCUMENT_ROOT"));
include "ws8_extensions.php";
include "ws8_functions.php";
What this is doing is adding the document root for your website to the include search path, and then you can include the files directly without referencing their location.
Cheers,
Paul Murphy
ServWise Advanced Hosting - Better, Faster, Smarter