Jump to content

help


AoNo

Recommended Posts

can someone explain how this works? im a newbie just need help :(

 

 

// setting up the web root and server root for

// this shopping cart application

$thisFile = str_replace('\\', '/', __FILE__);

$docRoot = $_SERVER['DOCUMENT_ROOT'];

 

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

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

 

define('WEB_ROOT', $webRoot);

define('SRV_ROOT', $srvRoot);

Link to comment
Share on other sites

The goal of this code is to create 2 constants to be used for including files from a known location, and for setting up url's.  In php you create constants with the define() function.

 

PHP has the $_SERVER superglobal that gets variables from apache and makes them available to php.  This is being used to help figure out the web root.

 

the __FILE__ is a magic php constant that provides the complete path and filename of the file in which it is called.  It is often used by a configuration script in a a known relative location, so that a basepath variable does not have to manually configured by the users of the scripts.

 

str_replace is being used to do some manipulation of the strings involved. 

 

You should take a look at the manual pages on php.net for hte functions that you don't understand. 

 

You can also echo or var_dump variables in the script to help you understand what value they hold when the script executes.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.