简体   繁体   中英

Get joomla 2.5 username using php and pass it to session or variable

I am a newbie here, I wanna learn php. I am using joomla2.5.9 right now, but i wanna get current username who logged in and put it in variable or maybe put it in a session. What i want from this current username is to create another script using php based on that current username.

first question : How can i Do that?
Second question: where should i put that 'first question' script in joomla2.5.9 folder?

Please Help... and thanks in advance..

By,

Leo

This PHP code, shows you the name of current user.

<?php $user =& JFactory::getUser(); $userName = $user->get( 'name' ); if ($user->get('guest') == 1) {} else { echo "Hi ".$userName."! Welcome to our great website!"; } ?>

You can put this code in your template files in: /templates/yourtemplatename/filewhereyouwanttoaddthis.php (in your case I think that you'll want to put this code in index.php - the principal layout of site)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM