Tuesday, March 30, 2010

Load the Joomla scripts in a Non-Joomla PHP Script


define( '_JEXEC', 1 );
define( '_VALID_MOS', 1 );
// JPATH_BASE should point to Joomla!'s root directory
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();
$user =& JFactory::getUser();
$session =& JFactory::getSession();

Joomla User Authentication Script For External websites

$query="SELECT password FROM `jos_users` WHERE username='".$_POST["userid"]."'";
$result = mysql_query($query);

if (mysql_num_rows($result)>0){
$dbpassword=mysql_result($result, 0);
mysql_close($link);
list($md5pass, $saltpass) = split(":", $dbpassword);
if ((md5($_POST["passwd"].$saltpass))==$md5pass) {
echo "Success" ;
} else {$messaggio="Password error:";}
}