Can I used Joomla's authentication system to allow/prevent access to a standalone script?
We've developed a few standalone php scripts and want to limit access to them. We use Joomla 1.5 as our main front end and I'm wondering if we can use the authentication from Joomla to determine if a user is logged in or not from within our application which is outside the Joomla framework. If we can avoid integrating the joomla framework into our code, it would be preferred.
Not being an expert on Joomla's authentication system, does anyone have any idea to tell whether a user is logged in or not? I assume we would look at the se开发者_JAVA百科ssion id and then use that to do a database query to see who the user is and if they're logged in?
There are some tools found at :
http://extensions.joomla.org/extensions/access-a-security/authentication-external
Which should be able to answer your question. From LDAP to NDIS, there are a variety of ways to make this happen.
This is late in the game, but in case someone else needs it.: You can access most of the Joomla Envrionment quite easily:
- Create a joomla platform file to include as shown below:
- Include that file in your script
yourscript.php
require_once('joomla_platform.php');
$user =& JFactory::getUser();
if($user->gid <25) {
die ("YOU CANT BE HERE");
}
joomla_platform.php
<?php
/* Force Debugging here, otherwise the loaded configuration will define it. */
define( 'JDEBUG', 1 );
/* If not already done, initialize Joomla framework */
if (!defined('_JEXEC')) {
define( '_JEXEC', 1 );
// define('JPATH_BASE', dirname(__FILE__) );
define ('JPATH_BASE', "c:\\wamp\\www\\hosted\\newday");
define( 'DS', DIRECTORY_SEPARATOR );
/* Required Files */
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/* To use Joomla's Database Class */
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
require_once ( JPATH_LIBRARIES.DS.'joomla'.DS.'import.php'); // Joomla library imports.
/* Create the Application */
global $mainframe;
$mainframe =& JFactory::getApplication('site');
global $mainframe;
}
/* $config = new JConfig(); */
/* $db = &JFactory::getDBO(); */
?>
精彩评论