简体   繁体   English

在另一个PHP脚本中使用joomla记帐

[英]using joomla accounting in another php script

I have a Joomla site and have a PHP script in it. 我有一个Joomla网站,其中有一个PHP脚本。 There is a button that redirects people to PHP script. 有一个按钮可以将人们重定向到PHP脚本。 I want to use my Joomla site user groups as access levels. 我想将我的Joomla网站用户组用作访问级别。 those who are not logged in should be prevented from accessing the index.php of the PHP script and receive a message such as "you must login first!" 这些谁没有登录应该访问PHP脚本的index.php文件 ,并收到一条消息,如防止“你必须登录!” and those that are logged in, can access to the index.php of the PHP script. 以及登录的用户可以访问PHP脚本的index.php

The thing that I did was that include the Joomla framework at the top of index.php of PHP script and put the function: JFactory::getUser(); 我要做的是在PHP脚本的index.php顶部包含Joomla框架,并放置以下函数: JFactory::getUser(); . After that I put the whole index.php in an if-else condition. 之后,我将整个index.php置于if-else条件下。 The condition of the if is that the return value of getUser() not equals "guest". if的条件是getUser()的返回值不等于“ guest”。

The else part is working properly and shows the message "you must login first" but the if part doesn't work and just shows a blank page and I receive # else部分工作正常,并显示消息“您必须先登录”,但是if部分不起作用,仅显示空白页,我收到#

error 500 "internal server error"

It means that my code recognises those that are logged in and those that aren't. 这意味着我的代码可以识别已登录和未登录的代码。 Also, when I delete my personal code it shows the index.php properly to everyone. 另外,当我删除个人代码时,它会向所有人正确显示index.php

help me pls 帮帮我


this is the code: 这是代码:

<?php



define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', dirname(__FILE__)."/../../../bt-travel/");

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .'/libraries/joomla/factory.php' );



$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

$user =& JFactory::getUser();

if(!$user->guest){



// *** check if database connection parameters file exists
if(!file_exists('include/base.inc.php')){
    header('location: install.php');
    exit;
}

## uncomment, if your want to prevent 'Web Page exired' message when use $submission_method = 'post';
// session_cache_limiter('private, must-revalidate');    
// *** set flag that this is a parent file

define('APPHP_EXEC', 'access allowed');


require_once('include/base.inc.php');
require_once('include/connection.php');




// *** call handler if exists
// -----------------------------------------------------------------------------
if((Application::Get('page') != '') && file_exists('page/handlers/handler_'.Application::Get('page').'.php')){
    include_once('page/handlers/handler_'.Application::Get('page').'.php');
}else if((Application::Get('customer') != '') && file_exists('customer/handlers/handler_'.Application::Get('customer').'.php')){
    if(Modules::IsModuleInstalled('customers')){    
        include_once('customer/handlers/handler_'.Application::Get('customer').'.php');
    }
}else if((Application::Get('admin') != '') && file_exists('admin/handlers/handler_'.Application::Get('admin').'.php')){
    include_once('admin/handlers/handler_'.Application::Get('admin').'.php');
}else if((Application::Get('admin') == 'export') && file_exists('admin/downloads/export.php')){
    include_once('admin/downloads/export.php');
}

// *** get site content
// -----------------------------------------------------------------------------
if(!preg_match('/booking_notify_/i', Application::Get('page'))){    
    $cachefile = '';
    if($objSettings->GetParameter('caching_allowed') && !$objLogin->IsLoggedIn()){
        $c_page        = Application::Get('page');
        $c_page_id     = Application::Get('page_id');
        $c_system_page = Application::Get('system_page');
        $c_album_code  = Application::Get('album_code');
        $c_news_id     = Application::Get('news_id');
        $c_customer    = Application::Get('customer');
        $c_admin       = Application::Get('admin');

        if(($c_page == '' && $c_customer == '' && $c_admin == '') || 
           ($c_page == 'pages' && $c_page_id != '') || 
           ($c_page == 'news' && $c_news_id != '') ||
           ($c_page == 'gallery' && $c_album_code != '')
           )
        {   
            $cachefile = md5($c_page.'-'.
                             $c_page_id.'-'.
                             $c_system_page.'-'.
                             $c_album_code.'-'.
                             $c_news_id.'-'.
                             Application::Get('lang').'-'.
                             Application::Get('currency_code')).'.cch'; 
            if($c_page == 'news' && $c_news_id != ''){
                if(!News::CacheAllowed($c_news_id)) $cachefile = '';
            }else{
                $objTempPage = new Pages((($c_system_page != '') ? $c_system_page : $c_page_id));
                if(!$objTempPage->CacheAllowed()) $cachefile = '';          
            }           
            if(start_caching($cachefile)) exit;
        }
    }
    require_once('templates/'.Application::Get('template').'/default.php');
    if($objSettings->GetParameter('caching_allowed') && !$objLogin->IsLoggedIn()) finish_caching($cachefile);
}

Application::DrawPreview();

echo "\n".'<!-- This page was generated by ApPHP Hotel Site v'.CURRENT_VERSION.' -->';

}else{
echo "you must login first";
}



?>
<?php



define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', dirname(__FILE__)."/../../../bt-travel/");

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .'/libraries/joomla/factory.php' );



$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

$user =& JFactory::getUser();

if(!$user->guest){



// *** check if database connection parameters file exists
if(!file_exists('include/base.inc.php')){
    header('location: install.php');
    exit;
}

## uncomment, if your want to prevent 'Web Page exired' message when use $submission_method = 'post';
// session_cache_limiter('private, must-revalidate');    
// *** set flag that this is a parent file

define('APPHP_EXEC', 'access allowed');


require_once('include/base.inc.php');
require_once('include/connection.php');




// *** call handler if exists
// -----------------------------------------------------------------------------
if((Application::Get('page') != '') && file_exists('page/handlers/handler_'.Application::Get('page').'.php')){
    include_once('page/handlers/handler_'.Application::Get('page').'.php');
}else if((Application::Get('customer') != '') && file_exists('customer/handlers/handler_'.Application::Get('customer').'.php')){
    if(Modules::IsModuleInstalled('customers')){    
        include_once('customer/handlers/handler_'.Application::Get('customer').'.php');
    }
}else if((Application::Get('admin') != '') && file_exists('admin/handlers/handler_'.Application::Get('admin').'.php')){
    include_once('admin/handlers/handler_'.Application::Get('admin').'.php');
}else if((Application::Get('admin') == 'export') && file_exists('admin/downloads/export.php')){
    include_once('admin/downloads/export.php');
}

// *** get site content
// -----------------------------------------------------------------------------
if(!preg_match('/booking_notify_/i', Application::Get('page'))){    
    $cachefile = '';
    if($objSettings->GetParameter('caching_allowed') && !$objLogin->IsLoggedIn()){
        $c_page        = Application::Get('page');
        $c_page_id     = Application::Get('page_id');
        $c_system_page = Application::Get('system_page');
        $c_album_code  = Application::Get('album_code');
        $c_news_id     = Application::Get('news_id');
        $c_customer    = Application::Get('customer');
        $c_admin       = Application::Get('admin');

        if(($c_page == '' && $c_customer == '' && $c_admin == '') || 
           ($c_page == 'pages' && $c_page_id != '') || 
           ($c_page == 'news' && $c_news_id != '') ||
           ($c_page == 'gallery' && $c_album_code != '')
           )
        {   
            $cachefile = md5($c_page.'-'.
                             $c_page_id.'-'.
                             $c_system_page.'-'.
                             $c_album_code.'-'.
                             $c_news_id.'-'.
                             Application::Get('lang').'-'.
                             Application::Get('currency_code')).'.cch'; 
            if($c_page == 'news' && $c_news_id != ''){
                if(!News::CacheAllowed($c_news_id)) $cachefile = '';
            }else{
                $objTempPage = new Pages((($c_system_page != '') ? $c_system_page : $c_page_id));
                if(!$objTempPage->CacheAllowed()) $cachefile = '';          
            }           
            if(start_caching($cachefile)) exit;
        }
    }
    require_once('templates/'.Application::Get('template').'/default.php');
    if($objSettings->GetParameter('caching_allowed') && !$objLogin->IsLoggedIn()) finish_caching($cachefile);
}

Application::DrawPreview();

echo "\n".'<!-- This page was generated by ApPHP Hotel Site v'.CURRENT_VERSION.' -->';

}else{
echo "you must login first";
}



?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM