Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to get the user id in an iframe in a joomla site (using virtual hosts). I'm using Joomla 3.9.3 with wamp 3.17 under win 10 pro (64 bit). my site resides in folder 'clib' under www.
As given in many forums, my php file using the iframe begins with the following code:
````
<?php

define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ] );

require_once( JPATH_BASE . '/clib/includes/defines.php' );
require_once( JPATH_BASE . '/clib/includes/framework.php' );
require_once( JPATH_BASE . '/clib/libraries/joomla/factory.php' );
$mf1 = JFactory::getApplication('site');

$user = JFactory::getUser();
$uname=$user->name;
$uid=$user->id;


?>

````

This works when accessing the site from localhost machine, but not when accessing from lan. All I need is the userid.

What I have tried:

This was working earlier when the site was in root folder using wamp 2.4 on win 8.2 and joomla 3.4.0 After updating the computer to win 10 pro, wamp 3.1.7 & joomla 3.9.4, same code doesn't work any longer. I've tried changing the path specified for 'defines.php', 'framework.php' & 'factory.php' to no avail.
Posted
Updated 5-May-19 7:47am
Comments
[no name] 5-May-19 17:10pm    
Run the old config on Win 10; then convert ... a piece at a time.
Member 10118655 6-May-19 2:43am    
I've tried that. Site doesn't restore properly on older joomla 3.4.0 due to error in backup (taken using akeeba). I had no alternative but to rebuild from scratch. Now everything is working fine except the iframe where user id is needed using the code given above. Strange thing is that the code works when logging into locally into localhost machine but not from LAN.

1 solution

Solved
Actually the solution is very simple. Since version 3.8 they have changed the access to user object somewhat.
I just modified the lines as under:
````
require_once( JPATH_BASE . '/libraries/joomla/factory.php' );

with

require_once ( JPATH_BASE . '/libraries/joomla/platform.php' );

and also approplraie changes in path:

define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ].'/clib' );
````
and la viola, everythings good.

Thanks Joomla guys and Codeproject friends.
 
Share this answer
 
Comments
[no name] 18-Jun-19 10:49am    
thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900