Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By o0Loco0o on
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
I would say the way you are
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