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
https://forums.phpfreaks.com/topic/254987-help/
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
https://forums.phpfreaks.com/topic/254987-help/#findComment-1307485
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.