Connecting to Joomla 1.5 from an external PHP script |
| Monday, 01 June 2009 | ||||
|
Sometimes you need to access Joomla libraries and/or data from an outside script. You may need to sync users with a 3PD application, or maybe you're developing a fresh application, but you're used to Joomla style JTable database manipulation, and JRequest input filtering. Here's the code to boot Joomla from an external script. Back when J! version was 1.5.7, this script was tested and working with PHP CLI(command line), too. I did not test with 1.5.10 for command line compatibility. Of course, the JDocument instance is not available, because we do not render anything, we're just initializing the application. The code sample below includes a simple login check. this login check will work as long as the connector script is hosted under the same directory as Joomla, because it will check cookies using HTTP path from the request URI. <?php define( '_JEXEC', 1 ); define( '_VALID_MOS', 1 ); // JPATH_BASE should point to Joomla root directory // if you app is placed into a subfolder in Joomla root, the path will look like dirname(__FILE__) . '/..' define( 'JPATH_BASE', realpath(dirname(__FILE__) .'/joomla1510' ) ); define( 'DS', DIRECTORY_SEPARATOR ); //as seen on http://forum.joomla.org/viewtopic.php?f=304&t=263491 require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); /** * check_joomla_login * * @return BOOL * @author Tudor * * USAGE EXAMPLE * echo (check_joomla_login())?"Logged in" : "Not logged in"; **/ function check_joomla_login(){ $mainframe =& JFactory::getApplication('site'); $mainframe->initialise(); // print_r($mainframe); $user =& JFactory::getUser(); // $session =& JFactory::getSession(); // debug print // print_r($user); // print_r($session); return ( (int)$user->id==0 )? FALSE:TRUE; }
Are you a Joomla/PHP/Web developer? You may want to check our list of freelance jobs websites.
This is perfect if you want to find out whether a user has logged into Joomla from an external script. thanks for point out Write Comment |
||||
| Last Updated ( Thursday, 18 June 2009 ) | ||||
Joomla stuff
Newsletter
Auto tags
external directory joomla
check user session joomla
joomla external login
php code connect in database joomla ?
JPATH_BASE
joomla login from external page
joomla framework einbinden externes script
joomla plugin in external script
joomla external login page
joomla login php
joomla 1.5 external login
joomla login from external
joomla external php
joomla login code
joomla login script
joomla php login
joomla php login check
joomla external php session
joomla login external
$mainframe->initialise();
$mainframe->initialise(); joomla
joomla 1.5 login.php








