Path info

We have a live system & a test system on the same host. The test system is at The live system is at

Apache server.

How can I determine, from within an executing php program, which one I'm in?

Richard KortsAsked:
Who is Participating?
Frosty555Connect With a Mentor Commented:
Look at the documentation for the $_SERVER superglobal array.

You'd be interested in the $_SERVER["PHP_SELF"] and $_SERVER["DOCUMENT_ROOT"] variables.

Also look at the __FILE__ magic constant
Richard KortsAuthor Commented:
To Frosty555

Thanks, I kind of remember that from previously.

I found another way. I know the base file in both systems is index.php. So I did this:

$path = realpath("index.php");
$lp = strlen($path);
$type = "prod";
for ($j = $lp - 1; $j >0; $j--) {
      if (substr($path,$j,1) == "/") {
            if (substr($path, $j-4,4) == "test") {
                  $type = "test";
echo $type;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.