There is a simple (main) script index.php :
<?php require 'cfg.php'; //файл с настройками require 'langs/' . $CFG['lang'] . '.php'; // языковой файл, прописаный в файле с настройками. Языковой файл содержит фразы в виде массива //echo 'P1>>>>>'; //var_dump($FO_LANG); //echo '<br>'; if(file_exists($CFG['auth'])) { //если есть файл с настройками авторизации //echo 'P2>>>>>'; //var_dump($FO_LANG); //echo '<br>'; include $CFG['auth']; //добавить его в скрипт //echo 'P3>>>>>'; //var_dump($FO_LANG); if ($fo_userid > 0) { //если юзерID > ноля echo $fo_userid; //вывести его ID } else { //если юзерID НЕ больше ноля var_dump ($FO_LANG['0002_fo_not_authorized']); // вывести второй элемент массива из языкового файла } } else { //если нет файла с настройками авторизации var_dump ($FO_LANG['0001_fo_cfg_file_not_exist']); //вывести первый элемент массива из языкового файла } ?> In the additional file langs/ru.php as you know, phrases are saved, in the form of an array:
<?php $FO_LANG = array ( '0001_fo_cfg_file_not_exist' => 'Не верная конфигурация.', '0002_fo_not_authorized' => 'Вы не авторизованы!', ); ?> The authorization file joomla_cfg.php , a standard script for retrieving the data of the current Joomla user.
define( '_JEXEC', 1 ); define('JPATH_BASE', dirname('../.') ); define( 'DS', DIRECTORY_SEPARATOR ); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); $mainframe =& JFactory::getApplication('site'); $mainframe->initialise(); $mainframe->route(); $user =& JFactory::getUser(); $fo_userid = $user->get('id'); The problem is that if the file_exists($CFG['auth']) condition file_exists($CFG['auth']) turns out to be false, then the phrase is correctly read from the array in the language file. And if it turns out to be true, and Joomla user data is "connected", then the array is not visible and var_dump NULL .
It is clear that you can once again include necessary files, but how to avoid this and correctly add an array, so that it would be visible in all cases within the main script?
cfg.php configuration cfg.php :
<?php $FO_CFG = array ( 'auth' => 'joomla_cfg.php', 'lang' => 'ru',, );