Joomla!
http://forum.joomla.org/

Extracting Joomla user name
http://forum.joomla.org/viewtopic.php?f=126&t=109473
Page 1 of 1

Author:  mattp [ Mon Oct 30, 2006 10:09 pm ]
Post subject:  Extracting Joomla user name

Hi,

I am pretty new to Joomla, but I am trying to get the current user name from Joomla for use within a PHP script using rd_addphp.

Is this possible??

TIA!!!
Matt

Author:  bpatient [ Sun Nov 05, 2006 2:46 pm ]
Post subject:  Re: Extracting Joomla user name

You would need the following:

Code:
global $my;

echo "My username: ".$my->username."<br />";

echo "My name: ".$my->name."<br />";


Well, depending which one you want.

8)

Author:  mattp [ Sun Nov 05, 2006 2:55 pm ]
Post subject:  Re: Extracting Joomla user name

Thanks bpatient!! It works a treat.

Author:  nhakhtn [ Tue Nov 07, 2006 8:42 am ]
Post subject:  Re: Extracting Joomla user name

And If i want to know the passwd ?
how do i do ?

Author:  ianmac [ Wed Nov 08, 2006 5:02 pm ]
Post subject:  Re: Extracting Joomla user name

Can't really do that...  the password is not stored in the database, only an MD5 hashed version (I think that is what it is).  when the password is sent, it is hashed and then compared with the stored hash value.

Ian

Author:  nhakhtn [ Thu Nov 09, 2006 2:51 am ]
Post subject:  Re: Extracting Joomla user name

Thanks !
can we store it in the session ?
if enable, could you present detail it. please !

Author:  ianmac [ Thu Nov 09, 2006 4:32 am ]
Post subject:  Re: Extracting Joomla user name

I'm not sure exactly what you are asking?

Are you working on the backend or the frontend?

I'm not sure offhand if the hashed password is stored in the $my object.  You would have to try it.
HINT: you can see all the data in the $my object using print_r( $my );  If password is blank (which it may be), then you'll probably have to get it right from the database.  Otherwise, you can get it right from the $my object (and then there isn't a real need to store it in the session, is there?)

Variables can be stored and retrieved from the session using $mainframe->setUserState() and $mainframe->getUserState or $mainframe->getUserStateFromRequest().  See joomla.php for more info (see the mosMainframe class, the methods I just mentioned).  This file is in the includes directory.

The session is only active on the back end.  user state doesn't work on the front end.

Hope that helps,
Ian

Author:  nhakhtn [ Fri Nov 10, 2006 2:10 am ]
Post subject:  Re: Extracting Joomla user name

Thank a lot !

Author:  swiep [ Mon May 28, 2007 3:37 pm ]
Post subject:  Re: Extracting Joomla user name

But how do you get the username or session id from the front end?

Author:  ianmac [ Mon May 28, 2007 3:53 pm ]
Post subject:  Re: Extracting Joomla user name

Read the thread again and you should find out how to get the username.

Why do you need the session ID?

Ian

Author:  swiep [ Mon May 28, 2007 4:17 pm ]
Post subject:  Re: Extracting Joomla user name

The session id would make it possible to find the username and that;s the only thing i care for, that a user has succesfuly logged on. This username will then be the primary key for the database needed for a project.

Author:  ianmac [ Mon May 28, 2007 4:56 pm ]
Post subject:  Re: Extracting Joomla user name

Then use the $my object.

If $my->id is 0, then no user is logged in.  Otherwise, the id is the user id of the currently logged in user.

$my->username will give you the username.

Sorry for the repetition here folks!
Ian

Author:  mreine [ Mon Jul 16, 2007 8:11 am ]
Post subject:  Re: Extracting Joomla user name

bpatient wrote:
You would need the following:

Code:
global $my;

echo "My username: ".$my->username."<br />";

echo "My name: ".$my->name."<br />";


Well, depending which one you want.

8)


Can you please give me an example php page for grabbing the username?  I see the example above but it is not working for me.  my code is below:

//include_once( '../globals.php' );
require_once( '../configuration.php' );
require_once( '../includes/joomla.php' );

global $my;

echo "My username: ".$my->username."
";

echo "My name: ".$my->name."
";

// Print an individual cookie
$cookie=  MD5( '64.merle.SuperAdministrator.1184563530' );
$name = $my->username;
echo $_COOKIE["devel.gardenfreshcorp.com"];
echo $HTTP_COOKIE_VARS["devel.gardenfreshcorp.com"];
echo $my->id;
echo $my->username;
echo $name;
echo $cookie;
echo "
";
echo $_USERNAME;
echo "
";
// Another way to debug/test is to view all cookies
print_r($_COOKIE);
?>

Author:  Ccrosaz [ Mon Jul 16, 2007 9:18 am ]
Post subject:  Re: Extracting Joomla user name

Hello all,

Quote:
Can you please give me an example php page for grabbing the username?  I see the example above but it is not working for me.  my code is below:

//include_once( '../globals.php' );
require_once( '../configuration.php' );
require_once( '../includes/joomla.php' );
...


I don't understand what you are trying to do... You want to use Joomla connected user info inside a non Joomla PHP page?

If your code is not in a joomla CMT (Component Miodule Template) that mean no user is currently connected...

If your code is in a Joomla CMT, then you does not need to call Joomla core files (configuration.php and joomla.php), because this is your CMT witch is call inside Joomla (and not the inverse)...

You can find $my object exemple in the mod_login.php module...

Author:  mreine [ Tue Jul 17, 2007 9:35 pm ]
Post subject:  Re: Extracting Joomla user name

Thanks for the reply.  I actually got it working.  I am using Flex 2 for a project to graph financial data.  Within the flash file, i am calling a php page to ascertain who is logged into joomla (our intranet) and that determines who has permission to do certain things with the data in flex.

I added the following to the templates/ja_altair/index.php and login.php(custom login page i made) and i am able to grab the username into flex:

$name = "$my->username";
setcookie("name",$name);
?>

I can then call the cookie named "name" to return the currently logged in user.  I know its not the proper way to do it,  but since joomla is so confusing with the session_id stuff and i read literally dozens upon dozens of posts all over the web of people wanting to do the same thing with no success, i had to do it this way.

Unless anyone can tell me an easier way, this will have to do.  I recently purchased a support suite called: "kayako" for $500.00 only to find out that it is not "integrated" with joomla as they claim.  It merely uses the same username/password as joomla requiring you to login twice.  Once for joomla and a second time for the support suite.  Since this is ridiculous, I wrote code within the joomla login to create the session and cookie for Kayako so that you are logged in from joomla into kayako without having to login in twice.  Would have been much easier if joomla's session login was explained somewhere so that normal people could figure it out.  I can assure you I am of above average intelligence but I could not make heads or tails of the joomla login.

Thanks for your timely reply.  Anyone heard of anyone making a module for Kayako and joomla integration?  Lots of people looking for this from the posts i read FYI.

Merle
IT Manager,
Souplantation

Author:  fm-soares [ Sat Sep 29, 2007 5:42 pm ]
Post subject:  Re: Extracting Joomla user name

If you use Joomla 1.0.12 or above use the loginShare, details in Kayako SupportSuite Manual

After 1.0.13 see http://forum.joomla.org/index.php/topic,217746.0.html

Author:  sonicth [ Sun Dec 09, 2007 11:49 pm ]
Post subject:  Re: Extracting Joomla user name

does anyone know how the "session_id" in the jos_session table is generated?

is it

md5(something + something else)?

Author:  sonicth [ Wed Dec 12, 2007 1:24 am ]
Post subject:  Re: Extracting Joomla user name

Ok, there IS a way...,

and its not made to be handled in a very simple manner at the present moment, and still NEEDS to be documented (the whole topic with username, authentication, session_id business - cannot find the documentation anywhere as of this moment :( ).

Concerning the cases outside of joomla (otherwise try the solutions above), there are no straightforward solutions, please email me mike.vasiljevs@gmail.com if you still have a problem

you might need to either modify joomla.php or create a bunch of fake classes etc in your external code just to trick joomla for some of the variables it expects to be available...

also my other post in http://forum.joomla.org/index.php/topic,242580.0.html
..on how to get 'session_id' and then simply SELECT the username from the jos_session table.
8)


mattp wrote:
I am pretty new to Joomla, but I am trying to get the current user name from Joomla for use within a PHP script using rd_addphp.

Is this possible??


Author:  top_cat [ Mon Mar 17, 2008 11:05 pm ]
Post subject:  Re: Extracting Joomla user name

mreine wrote:
Unless anyone can tell me an easier way, this will have to do.  I recently purchased a support suite called: "kayako" for $500.00 only to find out that it is not "integrated" with joomla as they claim.  It merely uses the same username/password as joomla requiring you to login twice.  Once for joomla and a second time for the support suite.  Since this is ridiculous, I wrote code within the joomla login to create the session and cookie for Kayako so that you are logged in from joomla into kayako without having to login in twice.  Would have been much easier if joomla's session login was explained somewhere so that normal people could figure it out.  I can assure you I am of above average intelligence but I could not make heads or tails of the joomla login.


Merle, did you manage to work out how to do this? It would be really great if this was workin

Author:  top_cat [ Sat Mar 22, 2008 1:30 am ]
Post subject:  Re: Extracting Joomla user name

Any update? have anyone got Kayako working with Joomla?

If any developer out there is interesting in developing this then contact me as I would be willing to pay....

Author:  mreine [ Sat Mar 22, 2008 6:34 am ]
Post subject:  Re: Extracting Joomla user name

Hello,

The following person/people report to have it working and I have emailed them as to the cost but no response yet. If you contact them and get any pricing, let me know and I will do the same.

http://forums.kayako.com/f78/joomla-kay ... tor-13692/

Author:  top_cat [ Sat Mar 22, 2008 11:23 am ]
Post subject:  Re: Extracting Joomla user name

mreine wrote:
Hello,

The following person/people report to have it working and I have emailed them as to the cost but no response yet. If you contact them and get any pricing, let me know and I will do the same.

http://forums.kayako.com/f78/joomla-kay ... tor-13692/


I contacted them an purchased the autologin but it works using an Joomla wrapper... This isn't want I wanted as running any page in a wrapper isn't ideal. Still looking for a real module which allows Kayako and Joomla to share information.

Author:  fm-soares [ Tue Apr 01, 2008 8:45 pm ]
Post subject:  Re: Extracting Joomla user name

top_cat wrote:
mreine wrote:
Hello,

The following person/people report to have it working and I have emailed them as to the cost but no response yet. If you contact them and get any pricing, let me know and I will do the same.

http://forums.kayako.com/f78/joomla-kay ... tor-13692/


I contacted them an purchased the autologin but it works using an Joomla wrapper... This isn't want I wanted as running any page in a wrapper isn't ideal. Still looking for a real module which allows Kayako and Joomla to share information.

Author:  fm-soares [ Tue Apr 01, 2008 8:48 pm ]
Post subject:  Re: Extracting Joomla user name

top_cat wrote:
mreine wrote:
Hello,

The following person/people report to have it working and I have emailed them as to the cost but no response yet. If you contact them and get any pricing, let me know and I will do the same.

http://forums.kayako.com/f78/joomla-kay ... tor-13692/



I contacted them an purchased the autologin but it works using an Joomla wrapper... This isn't want I wanted as running any page in a wrapper isn't ideal. Still looking for a real module which allows Kayako and Joomla to share information.

Author:  fm-soares [ Tue Apr 01, 2008 8:56 pm ]
Post subject:  Re: Extracting Joomla user name

About the last posts... (error quotes)

Hello men, i try to contact many developers to create a Joomla - Kayako Support Suite Bridge with no wrapper. If you can post your "autologin" with wrapper you can help!

If you paid for it and not have iterest in share you can port a url example. it very helpfull for the planning process.

Tks

Author:  mreine [ Wed Apr 02, 2008 4:08 pm ]
Post subject:  Re: Extracting Joomla user name

Latest conversation with kayako:

Hi,
>> When are you going to support joomla? And I don't mean your half baked joomla shared login that you have now. I mean a single signon with joomla when logged into joomla, it is logged into kayako? Hundreds of people are asking for it and i would think your company would want to appease its users.

I will forward this to the developers and if anything like this comes up, we will release it in News section and announcements in forums at http://forums.kayako.com Any inconvenience is deeply regretted.

Let us know if there is anything else we can assist you with.

Regards,

Varun Sharma

Author:  jalil [ Sun Apr 06, 2008 7:44 pm ]
Post subject:  Re: Extracting Joomla user name

could this be the reason for lack of response ?
it does not look like open source to me.

from Kayako site.
License Options
--------------------------------------------------------------------------------

There are four license options for you to choose from when purchasing SupportSuite, eSupport or LiveResponse. Licenses are on a per-installation basis - you are granted one installation for each license purchased. Additional licenses are available at a reduced cost, provided they are used by the same license holder (person, company or otherwise).

For yearly and monthly leased licenses, support and upgrades are available for as long as you hold the license for. For an owned license (a lifetime license), you will receive support and upgrades for 6 months. After this period (if you wish to continue receiving support and have access to new versions of the software) you will need to purchase another 6 months of support and upgrades. There is no obligation to renew and you will still be able to download the last version available to you.

Owned Yearly Leased Monthly Leased Monthly Hosted
Source code 98% Fully encrypted
Support 6 months Provided for as long as the license is held
Upgrades 6 months Provided for as long as the license is held
Hosted Your own web host or server Hosted for you
Seats Unlimited seats (staff) and users (clients)

Author:  jhoyos [ Tue Aug 11, 2009 7:26 pm ]
Post subject:  Re: Extracting Joomla user name

Hello , I tried

Code:
//include_once( '../globals.php' );
require_once( '../configuration.php' );
require_once( '../includes/joomla.php' );

global $my;

echo "My username: ".$my->username."
";

echo "My name: ".$my->name."
";


but it shows me "Restricted access" error , even if I'm logged
Thanks

Author:  geoff_m [ Sat Aug 29, 2009 8:10 pm ]
Post subject:  Re: Extracting Joomla user name

I hope it's appropriate to post here - but I have a similar situation and it is not working. I'm a real noob to Joomla, and getting the user name is a snap as are most things compared to figuring out how to be Joomla friendly. I'm a seasoned Perl, C/C++, MySQL web developer, but I am lost. So let me explain what I want to do and maybe you can give me some guidance.

On the main "page" of the site I want to have a link which will call a script (probably PHP since Joomla seems to prefer it). The script will access a mysql database and display some data in a table. Very simple to do in html and perl or php. However, I *need* the user name from Joomla in order to get the data which is user specific. I created a module which is running but does not work properly - but at least I know it runs. The problem is that it executes when the user logs on to the site. It's supposed to be run only by registered users - obviously after they have had a chance to login - and only if they want it. So the module should open a new window with the table data in it.

I have tried 2 approaches: one is simply a extension module and added an html link - from which I cannot extract the username using the $my... apparently $my is not accessible to a pure php script.

Tthe other attempt uses a Section/category - Similar to the "hello World" example in the "Professional Joomla" book by Dan Rahmel - but it executes when the main page is loaded - I need it to be selected manually.

So in essence I need to know:

How do I put a user selectable "link" to my module on the main page?

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/