Best Way To Use Same Files for Live and Local

I want to use the same files whether they are on my live server or on my test server.

I have a config file /includes/config.php that I load into each file

<?php require $_SERVER['DOCUMENT_ROOT'].'../includes/config.php';?>

When this file is loaded, it contains the paths for either local or live, Its just the trick of getting it to load.

On my test server the doc_root is C:\xampp\htdocs (but then in a difft folder /testsite)
On my live server the doc root is /home/live/live.net
What is the simplest way for me to achieve this with code I DON'T have to change if I were to load this site on any server?

Run this function and look at the output: getcwd() and then read the documentation about Directory Functions. You may find that the use of DOCUMENT_ROOT is not an advantage, but an impediment to developing a universal, correct path!

We use DOCUMENT_ROOT but we define it in a seperate file that is loaded using the prepend command in php.ini, the file is unique to the server not the website but it is one of only two files that need editing on the move from test to live, or in your case from local to live.

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Generally speaking, I try to build all my applications to use relative paths, so I generally avoid using DOCUMENT_ROOT or any specified "top folder" at all.

If I ever need to rely on an absolute path (not frequently), I use dirname(__FILE__) to get the current full path to the file that is executing that code, then I step up as necessary to get to the application's root folder.

It makes my applications VERY portable and makes it easy to establish testing and dev environments. It might be too late in this application (not sure how much code uses absolute paths), but I figured I would add my 2 cents.