We have a standalone script on our site that sits adjacent to a Joomla 1.5 installation. We are using Joomla authentication to restrict access to our script. At this point we are redirecting any unauthorized users to the Joomla site to log in. We want to add a login capability within our script, though. Does anyone know how to log into joomla from an external script using a username/password? Thanks!
A:
I would suggest one of the following solutions:
- Write a login plugin specific to your script.
- Using CURL in your script to do a POST-Request on the normal login form (CURL can cope cookies, too.)
- (Simplest): Do not authenticate by Joomla!, but by .htaccess.
giraff
2010-01-16 16:14:05
+1
A:
<?php
//http://domain.com/script/script.php?username=username&passwd=password
define( '_JEXEC', 1 );
define('JPATH_BASE', '../' );
define( 'DS', DIRECTORY_SEPARATOR );
require_once('../configuration.php');
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');
$credentials = array();
$credentials['username'] = JRequest::getVar('username', '', 'method', 'username');
$credentials['password'] = JRequest::getVar('passwd', '', 'method', 'passwd');
//preform the login action
$error = $mainframe->login($credentials);
$user = JFactory::getUser();
//now you are log in
$mainframe->logout();
//now you are log out
Perfect! That's exactly what I was looking for.
2010-02-18 18:59:13
A:
hi.. I am also having this doubt and i need step by step instructions for log in to joomla by external php page. I am new to joomla.
Please guide me to reach that...
selvamani
2010-06-04 12:42:34