I have a problem to retrieve the user id logged on joomla 1.5 from an external php script, I tried the following code but the problem is that sometimes it works very well and sometimes not work anymore :
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__).'/../..');
define( 'DS', DIRECTORY_SEPARATOR );
require_once( dirname(__FILE__) .'/../../libraries/loader.php' );
JLoader::import( 'joomla.factory');
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
require_once( dirname(__FILE__) .'/../../configuration.php' );
$row = new JConfig();
mysql_connect($row->host,$row->user,$row->password)
or die("erreur de connexion au serveur $$row->host");
mysql_select_db($row->db) or die("erreur de connexion a la base de donnees");
$user = &JFactory::getuser();
$iduser_f = $user->id;
$username = $user->username;
the problem is that $iduser_f sometimes return the id of user and lot of times returns 0.
Thank you for support
Hamid HASSAL
IT Developer