Hello everyone,
I have this php script that was originally meant to fetch data from a Joomla database and send it back to my application. It is very short, and I am having trouble figuring out the correct Drupal API methods to get it working properly. Would appreciate if someone could take a look, and possibly provide some input. Thank you very much for your time. Here's the script:

<?php
	define( '_JEXEC', 1 );
	define( 'JPATH_BASE', realpath(dirname(__FILE__)));
	define( 'DS', DIRECTORY_SEPARATOR );
	require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
	require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
	$mainframe = JFactory::getApplication('site');
	$mainframe->initialise();
	if(isset($_REQUEST['u'])){
		$username = $_REQUEST['u'];

	}else{
		$username = '';

	}

	if(isset($_REQUEST['p'])){
		$password = $_REQUEST['p'];

	}else{
		$password = '';

	}

	$user =& JUser::getInstance($username);

	if(user->block){
		$status = 1;
	}else{
		$status = 0;
	}
	$result = JFactory::getApplication()->login(array('username'=>$username,    'password'=>$password));
	if($result){
		echo '"status":"2","email":"' . $user->email . '","name":"' . $user->name .'"';
	}else{
		echo '"status":"' . $status .'","email":"0","name":"0"';
	}

?>

Comments

davidpham’s picture

I would say the way you are doing the coding is not "official", so that let 's fix it in Drupal version. You can follow this guide to create drupal module https://drupal.org/developing/modules and then use this drupal API to login as user you want

if ($uid = user_authenticate($username, $password)) {
      global $user;
      $user = user_load($uid);
      drupal_session_regenerate();
      $login_array = array ('name' => $username);
      user_login_finalize($login_array);
    }