Buy Now
Sign in

need to get current login username to my custom php

naresh , August 31 2011, 09:54
naresh 1
August 31 2011, 09:54 #75867
hi Every one,

is it possible to get current login user information from joomla to custom php file which also present in joomla root directory i tried but i get error please need urgently...


define( '_JEXEC', 1 );
define('JPATH_BASE', 'D:/xampp/community/' );
require_once ( DS.'includes'.DS.'defines.php' );
require_once ( DS.'includes'.DS.'framework.php' );

$mainframe =& JFactory::getApplication('site');

$user =& JFactory::getUser();

echo "user is".$user->username;

but i got error/ ...

Warning: require_once(\includes\defines.php) [function.require-once]: failed to open stream: No such file or directory in D:\xampp\htdocs\community\components\com_booklibrary\mybooks.php on line 9

Fatal error: require_once() [function.require]: Failed opening required '\includes\defines.php' (include_path='.;D:\xampp\php\PEAR') in D:\xampp\htdocs\community\components\com_booklibrary\mybooks.php on line 9

please help me..
Egorio 4
September 12 2011, 11:33 #85689
hm, that wil be interesting to know. but I can't even imagine how to do that. maybe admins will help...
admin 33
September 13 2011, 13:53 #89166

This is the code needed:

$user =& JFactory::getUser();

echo "user is ".$user->username;
lselbach 60
January 23 2012, 01:46 #264726
Hi there!
Just for helping newbies like me, the workaround I got for this was:

1. Open form in FORMS MANAGER.
2. Choose CODE tab
3. Inside the form code, found the INPUT BOX for username
4. Changed a little bit the original code for:

<input id="user" maxlength="150" size="30" class=" validate['required']" title="user" label_over="0" hide_label="0" type="text" value=<?php
$user =& JFactory::getUser();
echo $user->username;?> name="user" />

It worked fine.
Thanks again for this great extension.

Cheers from Brazil
Lucas Selbach
GreyHead 65
January 23 2012, 09:15 #264742
Hi Lucas,

There's a simpler way that doesn't required you to edit the Form HTML (if you do this then you can no longer use the Preview Box to eidt your form inputs).

Add a Custom Code action to the On Load event, drag it up before the Show HTML action and put this in it
$user =& JFactory::getUser();
$form->data['user'] = $user->username;

Make sure that the Show HTML action has 'Republish' set to 'Yes' (the default setting).


PS If you need more User info I have a Load User Info action that will grab it for you.
If you'd like to buy me a coffee or two, thank you very much