Page 1 of 1

Is this coding standard safe ?

Posted: Thu Jan 17, 2008 11:36 am
by jamestrix
I am helping my friend write a component and he has this line of code


include_once( $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR .'administrator'. DIRECTORY_SEPARATOR .'components'. DIRECTORY_SEPARATOR .'com_devtest'. DIRECTORY_SEPARATOR .'devtest.config.php');



Now it looks like he is using a server variable is that right to use a server variable or should he be using some thing like $mosConfig_absolute_path ? would the above work in a subdirectory ?

Re: Is this coding standard safe ?

Posted: Thu Jan 17, 2008 12:47 pm
by CirTap
Hi,

if the component is not supposed to be used by others, the code would be ok.
As soon as J! is installed in a subdirectory this line / component will certainly fail, thus $mosConfig_absolute_path is the right way to go for J! 1.0.x
I also found several bizarre hosters where $_SERVER['DOCUMENT_ROOT'] did not report the expected path, rendering this value pretty useless unreliable.

In J! 1.5 a bunch of additional path constants are made available to shorten (and standarddize) things a bit more:
  include_once JPATH_COMPONENT . DS . 'com_devtest' . DS .'devtest.config.php';

Have fun,
CirTap