Joomla user name variable in my URL

asked Sep 9, 2013 in Website Builder by jomnew

I am using Joomla 3.1 and I want to know if it is possible to get the value of a specific user name when the user clicks a button directing him to another page. I want the user name to show under $value
this is the button code
<a class="link-button" href="ex.php?usrname=$value">

I would appreciate any help on this

2 Answers

0 like 0 dislike
answered Sep 9, 2013 by JoomAp
For getting a user object use this line of code
$user =JFactory::getUser();

To  create the link use the code
<a href="ex.php?username=<?php echo $user->username; ?>">your link goes here</a>

now you need to add this 'if' statement to make the username pass only if a user is either logged or if the user exists
<?php $var = ($user->usrid ? '?username='.$user->yourusername : ''); ?>
<a href="ex.php<?php echo $var ?>">your link goes here</a>
0 like 0 dislike
answered Sep 9, 2013 by FixHost