I try to fetch my users information using the getUser() function with a php script located in a iframe (wrapper) of Joomla. It seems there is problem passing parameters to iframe code. The only way I can catch user informations is to insert the code into a basic article (which is not an iframe).
The var_dump($user); output shows :
object(JUser)#17 (23) { ["isRoot":protected]=> NULL ["id"]=> int(0) ["name"]=> NULL ["username"]=> NULL ["email"]=> NULL ["password"]=> NULL ["password_clear"]=> string(0) "" ["usertype"]=> NULL ["block"]=> NULL ["sendEmail"]=> int(0) ["registerDate"]=> NULL ["lastvisitDate"]=> NULL ["activation"]=> NULL ["params"]=> NULL ["groups"]=> array(0) { } ["guest"]=> int(1) ["_params":protected]=> object(JRegistry)#18 (1) { ["data":protected]=> object(stdClass)#19 (0) { } } ["_authGroups":protected]=> NULL ["_authLevels":protected]=> NULL ["_authActions":protected]=> NULL ["_errorMsg":protected]=> NULL ["_errors":protected]=> array(0) { } ["aid"]=> int(0) }
Some idea of what is going wrong ? Thank you, Florent
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$user = JFactory::getUser();
echo "<p>Your name is {$user->name}, your email is {$user->email}, and your username is $user->username}</p>";
echo "<p>Your usertype is {$user->usertype} which has a group id of {$user->gid}.</p>";
//var_dump($user);
?>
Of course, the page that includes the iframe doesn't "know" Joomla - it's a different environment!
If I understood correctly what you're trying to achieve, then you really should create an article in Joomla that displays the user information, but instead of getting the user-id from:
you should send it as POST/GET parameter from the OUTER page (you can add some kind of auth-string if security matters to you). The article will read this POST/GET parameter and display the user's information respectively.
The OUTER page (the one that contains the iframe) should refresh the iframe and use, as a url, the same url that displays the article (make sure it has "public" permissions) but will also send the user-id as parameter, for example:
hope it helps!
As previously said, wchen you use a wrapper, the Joomla environment is unknown. So you need to embed this before using Joomla API. To do this, just copy and paste this code (or create a new PHP file and include it in your custom page) :