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.
Write Comment |
||||
| Last Updated ( Thursday, 18 June 2009 ) | ||||
Joomla stuff
Newsletter
Auto tags
joomla external login
joomla login script
joomla php script
joomla login php
joomla external database
joomla external php
joomla insert php code
external login joomla
joomla mainframe
php in joomla article
joomla $mainframe
joomla login check
joomla JPATH_BASE
joomla check login
joomla php scripts
php script joomla
joomla external script
joomla php
joomla 1.5 Login check
joomla login from external page
joomla script
joomla user login check








