Showing posts with label php joomla external sign in. Show all posts
Showing posts with label php joomla external sign in. Show all posts

joomla external sign in

Wednesday, November 4, 2015

I am trying to login to the main joomla site from a xenforo site in the subdirectory of the joomla site i.e. www.joomlasite.com/xenforo/index.php?login/login
i have writtent the following code to login to the site:
xenforo login modification:



url = 'http://www.joomlasite.com/xenforo_login.php';
$fields = array(
'username' => urlencode($data['login']),
'password' => urlencode($data['password'])
);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);


and xenforo_login.php file in www.joomlasite.com/xenforo_login.php is as follows:



    define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );

require_once( JPATH_BASE .DS.'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');
jimport( 'joomla.user.user');
jimport( 'joomla.session.session');

$credentials = array();
$credentials['username'] = $_REQUEST['username'];
$credentials['password'] = $_REQUEST['password'];
//print_r($credentials);exit();

//perform the login action
$error = $mainframe->login($credentials);
$user = JFactory::getUser();


Now the issue I am facing is the code gives me the user but it does not login the user in the www.joomlasite.com nut the user is logged in www.joomlasite.com/xenforo
Can someone please help me asap!