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?

Thnks

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

/home/accountName/public_html/

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.