Is this coding standard safe ? Topic is solved

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
jamestrix

Is this coding standard safe ?

Post by jamestrix » Thu Jan 17, 2008 11:36 am

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 ?

User avatar
CirTap
Joomla! Intern
Joomla! Intern
Posts: 73
Joined: Mon Dec 12, 2005 5:34 pm
Contact:

Re: Is this coding standard safe ?

Post by CirTap » Thu Jan 17, 2008 12:47 pm

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
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams


Post Reply