I'm following a shopping cart tutorial and this snippet is confusing. I have a vague idea, but can some one pls explain what this means?

// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER;

$webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot = str_replace('library/config.php', '', $thisFile);

define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);

What are web and server roots?


11 Years
Discussion Span
Last Post by DanceInstructor

The webroot is the top level directory where files will be served to the web. For instance the directory structure may look like this:


In this case only files in public_html/ would be available to the people browsing the site. Also in this case I think they may be looking for a string to append to the begining of urls so the links in template files would point to the right place.

I think the server root in this case is probably the file path to the files used by the shopping cart.

In a more basic sense, the author doesn't expect the shopping cart to be placed in the top level directory and needed a way to determine what subfolders it is in.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.